gameLogic
Class Square

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

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

Objects of this class represent a single square of the game board. Each square has a List of all the GameObjects it contains, but it will usually only contain 0 or 1 GameObjects. The only time it can contain more than one game object is when a snake collides, with either a wall or another snake.

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

Method Summary
 java.util.ArrayList<Snake> getSnakes()
          Generates a list of all snakes in this square.
 boolean hasFruit()
          Returns whether or not this Square contains a fruit.
 boolean hasObjectType(java.lang.String typeName)
           
 boolean hasSnake()
          Returns whether or not this Square contains a snake.
 boolean hasWall()
          Returns whether or not this Square contains a wall.
 boolean isEmpty()
          Returns whether or not this Square is empty, e.g. has no game objects inside it.
 boolean isLethal()
          Checks if this square is lethal, e.g. if it contains a lethal GameObject.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEmpty

public boolean isEmpty()
Returns whether or not this Square is empty, e.g. has no game objects inside it.

Returns:
True if the square is empty, false if not.

hasObjectType

public boolean hasObjectType(java.lang.String typeName)

hasFruit

public boolean hasFruit()
Returns whether or not this Square contains a fruit. Checks by using hasObjectType.

Returns:
True if the square has a fruit, false if not.

hasSnake

public boolean hasSnake()
Returns whether or not this Square contains a snake.

Returns:
True if the square contains a snake, false if not.

hasWall

public boolean hasWall()
Returns whether or not this Square contains a wall. Checks by using hasObjectType.

Returns:
True if the square contains a wall, false if not.

isLethal

public boolean isLethal()
Checks if this square is lethal, e.g. if it contains a lethal GameObject.

Returns:
True if the square contains a wall, false if not.

getSnakes

public java.util.ArrayList<Snake> getSnakes()
Generates a list of all snakes in this square. Usually there is zero or one snake in the same square, but there can be more than one snake in the same square if one snake collides with another. It is therefore guaranteed that there cannot be more than one living snake in the same square.

Returns:
An ArrayList containing the snakes in this square, might be empty.