Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package g54368.humbug.model;
- import g54368.humbug.model.*;
- /**
- *
- * @author Akwatic
- */
- public class Spider extends Animal {
- // spider algo
- public Position move(Board board, Direction direction, Animal ... animals)
- {
- // get the current position
- Position position = getPositionOnBoard();
- while (true)
- {
- // get a ref sur our target position
- Position targetPosition = position.next(direction);
- Square square = null;
- // try getting the square at that position
- try
- {
- square = board.getSquareAtPosition(targetPosition);
- }
- // oob, we are out of the board
- catch (ArrayIndexOutOfBoundsException ex)
- {
- return null;
- }
- catch (IllegalArgumentException ex)
- {
- return null;
- }
- // square is null (= vide), we die
- if (square == null)
- {
- setPositionOnBoard(null);
- return null;
- }
- // check if the square is occupied by another animal
- else
- {
- for(Animal animal : animals)
- {
- // if so, stay where we are
- if(animal.getPositionOnBoard().equals(targetPosition))
- { System.out.print(" test 1 ");
- System.out.print(" test 2 ");
- if (square.getType() == SquareType.STAR)
- {
- System.out.print( "square type star 1 ");
- System.out.print(" square type star 2 ");
- square.setType(SquareType.GRASS);
- setOnStar();
- setPositionOnBoard(null);
- return position;
- }
- return position;
- }
- }
- // update our pos to the target position and we loop again
- position = targetPosition;
- setPositionOnBoard(position);
- }
- }
- }
- public Spider(Position position) {
- super(position);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement