2017-05-22 12 views
-2

내가 여기서 무슨 일이 일어나고 있는지하지 않습니다라고하지,하지만 motherclass의 이름을 딴 추상 메소드를 오버라이드 (override) 마지막 방법은서브 클래스 마지막 방법은

s.castable() 

호출되지 않습니다. MotherClass "맞춤법"여기

public void cast(String[] request) { 
    System.out.println("cast called"); 
    if (this.session.getPlayer()==this.game.getTurnPlayer()) { 
     System.out.println("first condition passed"); 
     Spell s = this.session.getPlayer().getCharacter().getSpells().get(Integer.valueOf(request[1])); 
     ArrayList<String> usernames = new ArrayList(); 
     System.out.println("Now printing spell: "+s); 

     for (int i = 6; i < request.length; i++) { 
      usernames.add(request[i]); 
     } 
     System.out.println("username create.d"); 
     if (s.castable()) {         //HERE 
      System.out.println("Second condition passed"); 
      s.cast(Integer.valueOf(request[1]), Integer.valueOf(request[2]),request[3].charAt(0), request[4].charAt(0), usernames); 
      String str = ""; 
      for (String st : usernames) { 
       str += st; 
      } 
      this.session.send("YOUSPELL "+request[1]+" "+request[2]+" "+request[3]+" "+request[4]+" "+str); 
      System.out.println("Done"); 
     } 
    } 
} 

: 나는 s.castable()를 호출 할 경우 다음

이다

public abstract class Spell { 

private int manaCost; 
private int coolDown; 
private int range; 
private Player player; 

public abstract void cast(int x, int y, char mode1, char mode2,ArrayList<String> usernames); 
public abstract Boolean castable(); 

//Then all getters and setters. 
} 

을 그리고 여기에 마지막 클래스 "속도"입니다 :

public final class Velocity extends Spell { 

private final int manaCost; 
private final Player player; 
private final int coolDown; 
private final int coolDownTime; 
private final int additionalMovement; 
private final int spellRef; 
private final ArrayList<String> usernames = new ArrayList(); 

public Velocity(Player p) { 
    this.spellRef = 0; 
    this.additionalMovement = 5; 
    this.player = p; 
    this.manaCost = 5; 
    this.coolDownTime = 3; 
    this.coolDown = 0; 
    super.setCoolDown(coolDown); 
    super.setManaCost(manaCost); 
    super.setPlayer(p); 
} 

@Override 
public final void cast(int x, int y, char mode1, char mode2,ArrayList<String> usernames) { 
    System.out.println("Velocity casted."); 
    player.setMovement(player.getMovement() + additionalMovement); 
    setCoolDown(coolDownTime); 
} 

@Override 
public final Boolean castable() { 
    System.out.println(player.getMana()); 
    System.out.println(manaCost); 
    System.out.println(getCoolDown()); 
    if (player.getMana() >= manaCost && getCoolDown() >= 0) { 
     return true; 
    } 
    return false; 
} 

} 

마지막으로, 콘솔 출력 :

,

cast called first condition passed Now printing spell: [email protected] username create.d.

당신이 마법의 객체가 알려져있다 볼 수 있듯이.

도와 주시겠습니까?

가 될 수 있습니다 여기

+0

내가 바로 여기에 손에 문제를 이해하지 않습니다. 당신이 출력을 참조하는 경우'model.haraka.be.Velocity @ 739bb60f' 당신은 그렇지 않으면'toString()를'재정의해야합니다 특정 문제를 명확히하거나 추가 정보를 추가하십시오. o 당신이 필요로하는 것을 정확히 강조합니다. –

+1

너무 많은 코드 :(A [최소한의 테스트 케이스]을 구성하십시오의에서 System.out.println (들)을 호출해야 얻을 만 (http://stackoverflow.com/help/mcve). –

+0

Aominè 없음 @입니다 s 객체는 Velocity의 instanceof입니다. 시도하고 할 수없는 것은 "s.castable()"메서드를 호출하는 것입니다. – GriffinBabe

답변

0

에게 유일하게 가능한 문제를 감사하는 추상 클래스 마법의 변수 sVelocity 객체에 대한 참조를 포함하지 않습니다.

따라서 castable 메서드는 결코 호출되지 않습니다. 내가 생각하는 경우가 아니라 System.out.println() 문을 인쇄해야 많은 사람들이 언급 한 바와 같이

castable method는 false를 반환됩니다.

이 문제입니다해야하는 그러나

, 설명해주십시오 : 방법을 아래에 무엇

Spell s = this.session.getPlayer().getCharacter().getSpells().get(Integer.valueOf(request[1])); 

유형을 반환?

  • getPlayer()
  • getSpells()는
  • GET (Integer.valueOf (요청 [1])

이 물어 너무 많이/코멘트 섹션에서 코멘트 따라서 int로서 게시 답.

+0

나의 나쁜, s.castable()이 호출되었지만 player.getMana(), manaCost 및 getCoolDown()이 아무 것도 반환하지 않는 것 같습니다. 내가 확신 할 때 나는 나의 해결책을 게시 할 것이다. – GriffinBabe