package model.entities; import model.world.Direction; import model.world.Position; /** * This class represent the player (the entity interacting with the user) * * */ public class Player extends AbsActive { private boolean alive; public Player() { // TODO Auto-generated constructor stub pos = new Position(0, 0); solid = true; alive = true; } /** * Compute the interaction with the Entity given */ @Override public void interact(IEntity entity) { if(entity instanceof Ghost) if (((Ghost) entity).pos.compareTo(this.pos) == 0) { System.out.println("I'm dead"); alive = false; } if(entity instanceof Door) { if(((Door) entity).pos.compareTo(this.pos) == 0) { System.out.println("I win!"); } } } /** * * @return true is the player still alive */ public boolean isAlive() { return alive; } /** * The methods had to be called when the player is not alive * and the user wants to continue to play. */ public void revive() { alive = true; setPos(new Position(0, 0)); } /** * @param d direction in which to move * This functions can not check if the move is valid because the player * is not aware of the size of the grid in which he evolves. The controller * must first check the validity of the move. */ @Override public void move(Direction d) { // TODO Auto-generated method stub pos = new Position(pos.x + d.dx, pos.y + d.dy); } }