org.almacha.achamaze
Class Maze

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

public class Maze
extends java.lang.Object

This class represents a maze.

Author:
Raphael Champeimont

Field Summary
private  int height
           
private  Cell[][] maze
           
private  int nextPlayerId
           
private  java.util.LinkedList<Player> players
           
private  int startColumn
           
private  int startLine
           
private  int width
           
 
Constructor Summary
Maze(int height, int width)
          This constructor creates a new maze.
 
Method Summary
 void addPlayer()
          Adds a player in the maze.
 boolean canMove(int i, int j, Direction d)
          Tells whether it is possible to move in direction d from cell (i, j).
 boolean cellExists(int i, int j)
          Returns whether the cell (i,j) exists in the maze.
 void checkCellExists(int i, int j)
          Raises a CellDoesNotExistException if and only if cellExists(i, j) is false.
private  Cell getCell(int i, int j)
           
 int getHeight()
          Returns the height (number of lines) of the maze.
 int getNumberOfPlayers()
          This method returns the number of players in the maze.
 Player getPlayer(int playerId)
           
 int getStartColumn()
          Returns the current start position (column).
 int getStartLine()
          Returns the current start position (line).
 int getWidth()
          Returns the width (number of columns) of the maze.
 boolean isFilled(int i, int j)
          Tells whether the cell (i,j) is filled.
 boolean isWallUp(int i, int j, Direction wall)
          This method returns whether a wall is up or not.
 void resetPlayers()
          Deletes all player in the maze.
 void setFilled(int i, int j, boolean filled)
          Sets whether a cell is filled or not.
 void setStartPosition(int i, int j)
          Defines the position at which new players start in the maze.
 void setWallIsUp(int i, int j, Direction wall, boolean isUp)
          This method sets whether a wall is there or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maze

private Cell[][] maze

height

private int height

width

private int width

players

private java.util.LinkedList<Player> players

nextPlayerId

private int nextPlayerId

startLine

private int startLine

startColumn

private int startColumn
Constructor Detail

Maze

public Maze(int height,
            int width)
     throws AchaMazeException
This constructor creates a new maze.

Parameters:
height - the number of lines, must be >= 1
width - the number of columns, must be >= 1
Throws:
AchaMazeException - thrown if width or height is invalid
Method Detail

cellExists

public boolean cellExists(int i,
                          int j)
Returns whether the cell (i,j) exists in the maze. This function does just check whether this cell is in the range.

Parameters:
i - the line number of the cell
j - the column number of the cell
Returns:
a boolean which tells you whether the cell exists

checkCellExists

public void checkCellExists(int i,
                            int j)
                     throws CellDoesNotExistException
Raises a CellDoesNotExistException if and only if cellExists(i, j) is false.

Parameters:
i - the line number of the cell
j - the column number of the cell
Throws:
CellDoesNotExistException - in case the cell does not exist

getCell

private Cell getCell(int i,
                     int j)
              throws CellDoesNotExistException
Throws:
CellDoesNotExistException

setWallIsUp

public void setWallIsUp(int i,
                        int j,
                        Direction wall,
                        boolean isUp)
                 throws CellDoesNotExistException
This method sets whether a wall is there or not.

Parameters:
i - the line of the cell whose wall you want to modify
j - the column of the cell whose wall you want to modify
wall - the wall of the cell you want to modify (North, Est, South or West)
isUp - whether you want to enable or disable this wall
Throws:
CellDoesNotExistException

isWallUp

public boolean isWallUp(int i,
                        int j,
                        Direction wall)
                 throws CellDoesNotExistException
This method returns whether a wall is up or not.

Parameters:
i - the line of the cell whose wall you want to know if it is up
j - the column of the cell whose wall you want to know if it is up
wall - the wall of the cell you want to look at (North, Est, South or West)
Returns:
a boolean telling you whether the wall is there or not
Throws:
CellDoesNotExistException - exception thrown if the required cell does not exist

getWidth

public int getWidth()
Returns the width (number of columns) of the maze.

Returns:
width of maze

getHeight

public int getHeight()
Returns the height (number of lines) of the maze.

Returns:
height of maze

setFilled

public void setFilled(int i,
                      int j,
                      boolean filled)
               throws CellDoesNotExistException
Sets whether a cell is filled or not. A filled cell prevents a player from going on that cell.

Parameters:
i - the line of the cell
j - the column of the cell
filled - wheter the cell should be filled (player cannot go on it) or empty (player can go on it)
Throws:
CellDoesNotExistException

isFilled

public boolean isFilled(int i,
                        int j)
                 throws CellDoesNotExistException
Tells whether the cell (i,j) is filled.

Parameters:
i - the line of the cell
j - the column of the cell
Returns:
a boolean telling whether the cell is filled or not
Throws:
CellDoesNotExistException - in case (i,j) is not a cell in the maze

addPlayer

public void addPlayer()
Adds a player in the maze.


resetPlayers

public void resetPlayers()
Deletes all player in the maze.


getNumberOfPlayers

public int getNumberOfPlayers()
This method returns the number of players in the maze.

Returns:
the number of players

getPlayer

public Player getPlayer(int playerId)

setStartPosition

public void setStartPosition(int i,
                             int j)
                      throws CellDoesNotExistException
Defines the position at which new players start in the maze.

Parameters:
i - line
j - column
Throws:
CellDoesNotExistException

getStartLine

public int getStartLine()
Returns the current start position (line).

Returns:
line

getStartColumn

public int getStartColumn()
Returns the current start position (column).

Returns:
column

canMove

public boolean canMove(int i,
                       int j,
                       Direction d)
                throws CellDoesNotExistException
Tells whether it is possible to move in direction d from cell (i, j).

Parameters:
i - line of the cell
j - column of the cell
d - direction where we want to go
Returns:
whether we can move
Throws:
CellDoesNotExistException - in case (i,j) is not a cell in the maze