org.almacha.achamaze
Class Player

java.lang.Object
  extended by org.almacha.achamaze.Player

public class Player
extends java.lang.Object

This class represents a player that is in the maze. You cannot create directly an object of this class, instead you have to use the addPlayer() method from the Maze class.

Author:
Raphael Champeimont

Field Summary
private  boolean inMaze
           
private  Maze maze
           
private  MazeSolvingAlgorithm mazeSolvingAlgorithm
           
private  int playerId
           
private  PlayerStateForMazeAlgo playerStateForMazeAlgo
           
private  int positionColumn
           
private  int positionLine
           
 
Constructor Summary
Player(Maze maze, int i)
           
 
Method Summary
 boolean canMove(Direction d)
          Tells whether the player can move in direction d.
 void checkIsInMaze()
          Throws PlayerNotInMazeException if player is not in maze.
 void exitMaze()
          Get player out of the maze.
 MazeSolvingAlgorithm getMazeSolvingAlgorithm()
          Returns the solving algorithm associated with the player.
 int getPlayerId()
          Get player id.
 int getPositionColumn()
          Returns the current position of the player.
 int getPositionLine()
          Returns the current position of the player.
 PlayerStateForMazeAlgo getStateForMazeAlgo()
           
 boolean isInMaze()
          Tells whether the player is in the maze.
 void move(Direction direction)
          Move in the requested direction.
 void setMazeSolvingAlgorithm(MazeSolvingAlgorithm mazeSolvingAlgorithm)
          Associates a maze solving algorithm to that player.
 void setPosition(int i, int j)
          Sets the current position of the player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

playerId

private int playerId

positionLine

private int positionLine

positionColumn

private int positionColumn

maze

private Maze maze

inMaze

private boolean inMaze

playerStateForMazeAlgo

private PlayerStateForMazeAlgo playerStateForMazeAlgo

mazeSolvingAlgorithm

private MazeSolvingAlgorithm mazeSolvingAlgorithm
Constructor Detail

Player

public Player(Maze maze,
              int i)
Method Detail

getPositionColumn

public int getPositionColumn()
                      throws PlayerNotInMazeException
Returns the current position of the player.

Returns:
column
Throws:
PlayerNotInMazeException

getPositionLine

public int getPositionLine()
                    throws PlayerNotInMazeException
Returns the current position of the player.

Returns:
line
Throws:
PlayerNotInMazeException

setPosition

public void setPosition(int i,
                        int j)
                 throws CellDoesNotExistException
Sets the current position of the player. This puts the player back in the maze, so isInMaze() will then return true.

Parameters:
i - line
j - column
Throws:
CellDoesNotExistException - in case (i,j) does not exist

exitMaze

public void exitMaze()
Get player out of the maze. Method isInMaze() will then return false.


canMove

public boolean canMove(Direction d)
Tells whether the player can move in direction d. It always returns false if player is not in maze.

Parameters:
d - direction where we want to know if we can move
Returns:
whether it is possible

move

public void move(Direction direction)
          throws PlayerCannotMoveException
Move in the requested direction.

Parameters:
direction -
Throws:
PlayerCannotMoveException - in case we cannot move in this direction

isInMaze

public boolean isInMaze()
Tells whether the player is in the maze.

Returns:
whether or not player is in the maze

checkIsInMaze

public void checkIsInMaze()
                   throws PlayerNotInMazeException
Throws PlayerNotInMazeException if player is not in maze.

Throws:
PlayerNotInMazeException - in case player is not in maze

getPlayerId

public int getPlayerId()
Get player id.

Returns:
player id

getStateForMazeAlgo

public PlayerStateForMazeAlgo getStateForMazeAlgo()

getMazeSolvingAlgorithm

public MazeSolvingAlgorithm getMazeSolvingAlgorithm()
Returns the solving algorithm associated with the player. It returns null if there is none.

Returns:
the algorithm

setMazeSolvingAlgorithm

public void setMazeSolvingAlgorithm(MazeSolvingAlgorithm mazeSolvingAlgorithm)
                             throws AchaMazeException
Associates a maze solving algorithm to that player. This is just for convenience, to store the algorithm reference with the player. This method will check that the given algorithm is associated with this player state.

Parameters:
mazeSolvingAlgorithm - a instance of maze solving algorithm
Throws:
AchaMazeException - in case the algorithm is associated to another player