Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Grid{
- public static final int UNKNOWN = 0;
- public static final int HIT = 1; //true
- public static final int MISS = 2; //false
- public static final int GRIDSIZE = 10;
- /* array holding status of each grid location */
- int [][] grid = new int[GRIDSIZE][GRIDSIZE];
- public Grid(){
- //Setting UNKNOWN values
- for(int row = 0; row < GRIDSIZE; row++)
- for(int column = 0; column < GRIDSIZE; column++){
- grid[row][column] = 0;
- }
- }
- public void print(){
- int [][] grid = new int[GRIDSIZE][GRIDSIZE];
- System.out.print("\n");
- for(int row = 0; row < GRIDSIZE; row++){
- System.out.print("\n");
- for(int column = 0; column < GRIDSIZE; column++){
- System.out.print(grid[row][column] + "\t");
- }
- }
- }
- public void set(int row, int column, int status) {
- //Outside boundary error
- if((row >= GRIDSIZE) || (row < 0)){
- System.out.println("Row value is out of bounds.");
- }else{
- if((column >= GRIDSIZE) || (column < 0)){
- System.out.println("Column value is out of bounds.");
- }else{
- //Set HIT or MISS
- grid[row][column] = status;
- }
- }
- }
- public static void main(String []args) {
- Grid g = new Grid();
- g.set(0,0,HIT);
- g.set(1,1,MISS);
- g.print();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement