Class Grid

java.lang.Object
  extended by Grid

public class Grid
extends java.lang.Object

The grid class manages the the grid and the location of all the objects in said grid.

Author:
daniel

Field Summary
private  int height
           
private  java.util.ArrayList<Obj>[][] map
           
private  int width
           
 
Constructor Summary
Grid()
          Creates the grid in which players interact.
 
Method Summary
 void add(int x, int y, Obj obj)
          Adds the object passed into the grid at the specified location.
 boolean containsBomb(int x, int y)
          Checks if the location x,y has a bomb there.
 java.util.ArrayList<Obj> get(int row, int col)
          Returns an Arraylist of objects in the grid at position (row, col).
 java.util.ArrayList<int[]> getEmpty()
          Returns all the empty locations in the grid, as an integer array { x, y }
 int getHeight()
          Returns the height of the grid.
 java.util.ArrayList<Obj> getOccupied()
          Returns all the objects on the Grid.
 int getWidth()
          Returns the width of the grid.
 boolean isValid(int x, int y)
          Determines whether or not the location in the grid is valid.
 int[] randomLocation()
          Returns a single random location that is empty.
 void remove(Obj obj, int x, int y)
          Removes the specified object at the specified location in the grid.
 void removeAll()
          Removes everything
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private java.util.ArrayList<Obj>[][] map

width

private final int width
See Also:
Constant Field Values

height

private final int height
See Also:
Constant Field Values
Constructor Detail

Grid

public Grid()
Creates the grid in which players interact. Defaults to a 13 by 9 grid.

Method Detail

get

public java.util.ArrayList<Obj> get(int row,
                                    int col)
Returns an Arraylist of objects in the grid at position (row, col). If location is invalid, returns null.

Parameters:
row - the x-coordinate of the location to get objects
col - the y-coordinate of the location to get objects
Returns:
a list of all objects at specified location

getOccupied

public java.util.ArrayList<Obj> getOccupied()
Returns all the objects on the Grid.

Returns:
all the objects on the Grid.

getEmpty

public java.util.ArrayList<int[]> getEmpty()
Returns all the empty locations in the grid, as an integer array { x, y }

Returns:
all the empty locations in the grid

isValid

public boolean isValid(int x,
                       int y)
Determines whether or not the location in the grid is valid.

Parameters:
x - x-coordinate to check
y - y-coordinate to check
Returns:
true if (x,y) is in the grid

add

public void add(int x,
                int y,
                Obj obj)
Adds the object passed into the grid at the specified location.

Parameters:
x - x-coordinate at which to add object
y - y-coordinate at which to add object
obj - object to add to the grid

remove

public void remove(Obj obj,
                   int x,
                   int y)
Removes the specified object at the specified location in the grid.

Parameters:
x - x-coordinate of object which to delete
y - y-coordinate of object which to delete

removeAll

public void removeAll()
Removes everything


randomLocation

public int[] randomLocation()
Returns a single random location that is empty.


containsBomb

public boolean containsBomb(int x,
                            int y)
Checks if the location x,y has a bomb there. Returns true if there is.

Parameters:
x -
y -
Returns:
true if there is a bomb

getWidth

public int getWidth()
Returns the width of the grid.

Returns:
width

getHeight

public int getHeight()
Returns the height of the grid.

Returns:
height