gameLogic
Class Board

java.lang.Object
  extended by gameLogic.Board
All Implemented Interfaces:
java.io.Serializable

public class Board
extends java.lang.Object
implements java.io.Serializable

This class represents the entire game board through a 2D-array of Square objects. Each Square, in turn, contains GameObjects, such as fruits, walls, or other snakes.

Author:
Sixten Hilborn, Arian Jafari
See Also:
Square, Serialized Form

Method Summary
 int getHeight()
          Gets the height of the board (the 2D-array).
 Square getSquare(Position p)
          Gets a Square at
 int getWidth()
          Gets the width of the board (the 2D-array).
 boolean hasFruit(Position p)
          Returns whether or not the board contains a fruit at the given position.
 boolean hasGameObject(Position p)
          Returns whether or not the board contains any game object at the given position.
 boolean hasLethalObjectWithinRange(Position pos, int range)
          Calculates whether or not the board contains a lethal object within a given radius of a certain square.
 boolean hasSnake(Position p)
          Returns whether or not the board contains a snake at the given position.
 boolean hasWall(Position p)
          Returns whether or not the board contains a wall at the given position.
 boolean isLethal(Position p)
          Returns whether or not the board contains a lethal game object at the given position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getWidth

public int getWidth()
Gets the width of the board (the 2D-array).

Returns:
The width of the board.

getHeight

public int getHeight()
Gets the height of the board (the 2D-array).

Returns:
The height of the board.

hasGameObject

public boolean hasGameObject(Position p)
Returns whether or not the board contains any game object at the given position. Doesn't perform any checks on what type of object it is, like if it is lethal or not.

Parameters:
p - The position we want to check for game objects.
Returns:
Whether or not the board contains a game object at the given position.

hasFruit

public boolean hasFruit(Position p)
Returns whether or not the board contains a fruit at the given position.

Parameters:
p - The position we want to check for fruit.
Returns:
Whether or not the board contains a fruit at the given position.

hasWall

public boolean hasWall(Position p)
Returns whether or not the board contains a wall at the given position.

Parameters:
p - The position we want to check for walls.
Returns:
Whether or not the board contains a wall at the given position.

hasSnake

public boolean hasSnake(Position p)
Returns whether or not the board contains a snake at the given position.

Parameters:
p - The position we want to check for snakes.
Returns:
Whether or not the board contains a snake at the given position.
See Also:
Square

isLethal

public boolean isLethal(Position p)
Returns whether or not the board contains a lethal game object at the given position.

Parameters:
p - The position we want to check for lethal objects.
Returns:
Whether or not the board contains a lethal game object at the given position.
See Also:
Square

getSquare

public Square getSquare(Position p)
Gets a Square at

Parameters:
p - The position in the board where we want to get the Square from.
Returns:
The Square at the specified position.
See Also:
Square

hasLethalObjectWithinRange

public boolean hasLethalObjectWithinRange(Position pos,
                                          int range)
Calculates whether or not the board contains a lethal object within a given radius of a certain square. Works by using a depth-first search.

Parameters:
pos - The position which we want to check.
range - The number of squares we wish to examine, e.g. the radius of the area we want to check.
Returns:
A boolean indicating whether or not there is a lethal object within the given range of the specified position.