Здравствуйте!
Не проходит проверку, всё перепроверил, но ликвидатор ругается.
package com.javarush.task.task13.task1328;
public abstract class AbstractRobot implements Attackable, Defensable{
private static int hitCount;
private String name;
public AbstractRobot(String name) {
this.name = name;
}
public String getName() {
return name;
}
public BodyPart attack() {
BodyPart attackedBodyPart = null;
hitCount = hitCount + 1;
if (hitCount == 1) {
attackedBodyPart = BodyPart.ARM;
} else if (hitCount == 2) {
attackedBodyPart = BodyPart.HEAD;
} else if (hitCount == 3) {
attackedBodyPart = BodyPart.LEG;
} else if (hitCount == 4 ){
hitCount = 0;
attackedBodyPart = BodyPart.CHEST;
}
return attackedBodyPart;
}
public BodyPart defense() {
BodyPart defencedBodyPart = null;
hitCount = hitCount + 1;
if (hitCount == 1) {
defencedBodyPart = BodyPart.HEAD;
} else if (hitCount == 2) {
defencedBodyPart = BodyPart.LEG;
} else if (hitCount == 3) {
defencedBodyPart = BodyPart.ARM;
} else if (hitCount == 4){
hitCount = 0;
defencedBodyPart = BodyPart.CHEST;
}
return defencedBodyPart;
}
}
package com.javarush.task.task13.task1328;
/*
Битва роботов
*/
public class Solution {
public static void main(String[] args) {
Robot amigo = new Robot("Амиго");
Robot enemy = new Robot("Сгибальщик-02");
doMove(amigo, enemy);
doMove(amigo, enemy);
doMove(enemy, amigo);
doMove(amigo, enemy);
doMove(enemy, amigo);
doMove(amigo, enemy);
doMove(enemy, amigo);
doMove(amigo, enemy);
}
public static void doMove(AbstractRobot robotFirst, AbstractRobot robotSecond) {
BodyPart attacked = robotFirst.attack();
BodyPart defenced = robotFirst.defense();
System.out.println(String.format("%s атаковал робота %s, атакована %s, защищена %s",
robotFirst.getName(), robotSecond.getName(), attacked, defenced));
}
}