Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package animal;
- import java.util.ArrayList;
- import utils.Cell;
- import utils.Util;
- public class Frog extends Animal{
- private static final int BONUS_STEP;
- private int actualBonus;
- static{
- BONUS_STEP = 3;
- }
- public Frog(String signal, Position position) {
- super(signal, position);
- actualBonus = 0;
- }
- @Override
- public void eat(Animal food) {
- super.eat(food);
- actualBonus = BONUS_STEP;
- }
- @Override
- public void move() {
- int stepCount = actualBonus>0? 2 : 1;
- if (actualBonus>0){
- actualBonus--;
- if (actualBonus==0){
- signal = "B";
- }
- }
- for (int i = 0; i < stepCount; i++) {
- ArrayList<Cell> surroundingCells = Util.surroundingCells(position, 1);
- Cell cell;
- do {
- cell = surroundingCells.get(RANDOM.nextInt(surroundingCells.size()));
- } while (cell.getAnimal() instanceof Stork);
- if (cell.getAnimal() instanceof Fly){
- eat(cell.getAnimal());
- signal = "Z";
- }
- position = cell.getPosition();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement