Class Grid

java.lang.Object
  extended by Grid

public class Grid
extends java.lang.Object


Field Summary
private  Space[][] grid
           
(package private)  int guix
           
(package private)  int guiy
           
(package private)  int height
           
(package private)  int length
           
 
Constructor Summary
Grid(int l, int h, int who)
          The Grid class is where the grid matrix is created for the grid classes
 
Method Summary
 int checkCord(int row, int col, int o, int sLength)
          Used to check a to see if a ship goes off the grid
 int checkspot(int row, int col)
          Used to check to see if the selected space has been already hit or miss
 int getGX()
          Used to get the row coordinate for the grid buttons for when the AI shoots
 int getGY()
          Used to get the col coordinate for the grid buttons for when the AI shoots
 char LetterNum(int letter)
          Used to convert coordinates to letters
 void printFullGrid()
          Used to print out a full battleship grid displaying ships for one player
 java.lang.String printGrid(int row, int col)
          Used to print the grids to display where ships are on the grid buttons
 void setGX(int gx)
          Used to set up the row coordinate for the grid buttons for when the AI shoots
 void setGY(int gy)
          Used to set up the col coordinate for the grid buttons for when the AI shoots
 int setupShips(int player, int type, int sLength, int row, int col, int o)
          This sets up the ships on the grid for both players
 int shipCheckH(int cCol, int row, int sLength)
          Used to check to see if a ship comes in conflict with another ship horizontally
 int shipCheckV(int col, int rRow, int sLength)
          Used to check to see if a ship comes in conflict with another ship vertically
 java.lang.String shipHit(int row, int col)
          Used to get the ship that was hit
 int shoot(int row, int col)
          Used to check to see if a ship is at a point being shot at
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

int length

height

int height

guix

int guix

guiy

int guiy

grid

private Space[][] grid
Constructor Detail

Grid

public Grid(int l,
            int h,
            int who)
The Grid class is where the grid matrix is created for the grid classes

Parameters:
l - - This is the length size of the grid
h - - This is the height size of the grid
who - - This identifies who belongs to the grid
Method Detail

setupShips

public int setupShips(int player,
                      int type,
                      int sLength,
                      int row,
                      int col,
                      int o)
This sets up the ships on the grid for both players

Parameters:
player - - determines what player is setting up the shups
type - - identifies which ship is being setup
sLength - - The length of the ship
row - - The starting row coordinate for the placement of the ship
col - - The starting column coordinate for the placement of the ship
o - - the orientation of the ship, vertical or horizontal
Returns:
true if the ship is placed successfully without hitting another ship or going off the grid

printFullGrid

public void printFullGrid()
Used to print out a full battleship grid displaying ships for one player


shipCheckH

public int shipCheckH(int cCol,
                      int row,
                      int sLength)
Used to check to see if a ship comes in conflict with another ship horizontally

Parameters:
cCol - - column coordinate of the starting spot for the ship
row - - row coordinate of the starting spot of the grid
sLength - - The length of the ship being placed
Returns:
true if ship doesn't have any conflicts if not, returns a 2 to signify conflict

shipCheckV

public int shipCheckV(int col,
                      int rRow,
                      int sLength)
Used to check to see if a ship comes in conflict with another ship vertically

Parameters:
col - - column coordinate of the starting spot for the ship
rRow - - row coordinate of the starting spot of the grid
sLength - - The length of the ship being placed
Returns:
true if ship doesn't have any conflicts if not, returns a 2 to signify conflict

LetterNum

public char LetterNum(int letter)
Used to convert coordinates to letters

Parameters:
letter - - the number passed to be converted to a letter
Returns:
the converted character for that number

checkCord

public int checkCord(int row,
                     int col,
                     int o,
                     int sLength)
Used to check a to see if a ship goes off the grid

Parameters:
col - - column coordinate of the starting spot for the ship
row - - row coordinate of the starting spot of the grid
o - - the orientation of the ship, vertical or horizontal
sLength - - The length of the ship being placed
Returns:
true if ship doesn't have any conflicts

shoot

public int shoot(int row,
                 int col)
Used to check to see if a ship is at a point being shot at

Parameters:
col - - column coordinate of the starting spot for the ship
row - - row coordinate of the starting spot of the grid
Returns:
true if a ship has been hit

shipHit

public java.lang.String shipHit(int row,
                                int col)
Used to get the ship that was hit

Parameters:
col - - column coordinate of the starting spot for the ship
row - - row coordinate of the starting spot of the grid
Returns:
the ship that was hit

checkspot

public int checkspot(int row,
                     int col)
Used to check to see if the selected space has been already hit or miss

Parameters:
col - - column coordinate of the starting spot for the ship
row - - row coordinate of the starting spot of the grid
Returns:
true if the spot is free and shootable

printGrid

public java.lang.String printGrid(int row,
                                  int col)
Used to print the grids to display where ships are on the grid buttons

Parameters:
col - - the row spot of the ship
row - - the column spot of the ship
Returns:
the charracter associated with that spot

setGX

public void setGX(int gx)
Used to set up the row coordinate for the grid buttons for when the AI shoots

Parameters:
gx - - the row coordinate for the gui button

setGY

public void setGY(int gy)
Used to set up the col coordinate for the grid buttons for when the AI shoots

Parameters:
gy - - the col coordinate for the gui button

getGY

public int getGY()
Used to get the col coordinate for the grid buttons for when the AI shoots

Returns:
returns the current column location to the grid button to display its status

getGX

public int getGX()
Used to get the row coordinate for the grid buttons for when the AI shoots

Returns:
returns the current row location to the grid button to display its status