So I'm trying to create a critter code for a bird. I'm having trouble with the movement though. So it moves 3 steps in a north direction, then moves 3 steps in east, then south 3 and then west 3. I am trying to create an if/else based on this fact but I'm having trouble constructing one that will account for the directional changes. I'm trying to solve what the if else would be based on this pattern:
step 1 ^ (direction)
step 2 ^
step 3 ^
step 4 >
step 5 >
step 6 >
step 7 V
step 8 V
step 9 V
step 10 <
step 11 <
step 12 <
import java.awt.*;
public class Bird extends Critter {
int length = 3;
int step = 0;
Direction original = Direction.NORTH;
// method comment goes here
public Attack fight(String opponent) {
if (opponent == %) {
return Attack.ROAR;
}else{
return Attack.POUNCE;
}
}
// method comment goes here
public Color getColor() {
return Color.BLUE;
}
// method comment goes here
public String toString() {
return "V";
}
public boolean eat() {
return false;
}
public Direction getMove(){
++step;
if (step < length) {
direction = original;
} else if (step == length) {
direction = Direction.EAST;
}
return direction;
}
}
Aucun commentaire:
Enregistrer un commentaire