내가 여기서 무슨 일이 일어나고 있는지하지 않습니다라고하지,하지만 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
.
당신이 마법의 객체가 알려져있다 볼 수 있듯이.
도와 주시겠습니까?
가 될 수 있습니다 여기
내가 바로 여기에 손에 문제를 이해하지 않습니다. 당신이 출력을 참조하는 경우'model.haraka.be.Velocity @ 739bb60f' 당신은 그렇지 않으면'toString()를'재정의해야합니다 특정 문제를 명확히하거나 추가 정보를 추가하십시오. o 당신이 필요로하는 것을 정확히 강조합니다. –
너무 많은 코드 :(A [최소한의 테스트 케이스]을 구성하십시오의에서 System.out.println (들)을 호출해야 얻을 만 (http://stackoverflow.com/help/mcve). –
Aominè 없음 @입니다 s 객체는 Velocity의 instanceof입니다. 시도하고 할 수없는 것은 "s.castable()"메서드를 호출하는 것입니다. – GriffinBabe