Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ShipProps
- {
- public static boolean canPlace (int locX, int locY, int[][] grid)
- {
- boolean canPlace;
- boolean[][] gridTorF = new boolean[9][9];
- int[][] locTest = {{1},{1}};
- if (locTest[0][0] == (grid[locX][locY]))
- {
- canPlace = false;
- }
- else
- {
- canPlace = true;
- }
- if(canPlace = true)
- {
- for(int i = 0; i < 10; i++)
- {
- if(locX == i)
- {
- for(int i2 = 0; i2 < 10; i2++)
- {
- if(locY == i2)
- {
- grid[locX][locY] = 1;
- }
- }
- }
- }
- return canPlace;
- }
- else
- {
- return canPlace;
- }
- }
- public static int[][] displayOptions (int length, int startLocX, int startLocY, int[][] grid)
- {
- boolean canPlace = false;
- if (canPlace(startLocX, startLocY, grid))
- {
- System.out.println("You can place your ship!");
- System.out.println();
- System.out.println("Which way would you like your ship to face?");
- System.out.println();
- if( canPlace(startLocX, startLocY + (length - 4), grid) == true && canPlace(startLocX, startLocY + (length - 3), grid) == true && canPlace(startLocX, startLocY + (length - 2), grid) == true && canPlace(startLocX, startLocY + (length - 1), grid) == true && canPlace(startLocX, startLocY + length, grid) == true )
- {
- System.out.print("Up?");
- canPlace = true;
- }
- if( canPlace(startLocX, startLocY - (length - 4), grid) == true && canPlace(startLocX, startLocY - (length - 3), grid) == true && canPlace(startLocX, startLocY - (length - 2), grid) == true && canPlace(startLocX, startLocY - (length - 1), grid) == true && canPlace(startLocX, startLocY - length, grid) == true )
- {
- System.out.print(" Down?");
- canPlace = true;
- }
- if( canPlace(startLocX - (length - 4), startLocY, grid) == true && canPlace(startLocX - (length - 3), startLocY, grid) == true && canPlace(startLocX - (length - 2), startLocY, grid) == true && canPlace(startLocX - (length - 1), startLocY, grid) == true && canPlace(startLocX - length, startLocY, grid) == true )
- {
- System.out.print(" Left?");
- canPlace = true;
- }
- if( canPlace(startLocX + (length - 4), startLocY, grid) == true && canPlace(startLocX + (length - 3), startLocY, grid) == true && canPlace(startLocX + (length - 2), startLocY, grid) == true && canPlace(startLocX + (length - 1), startLocY, grid) == true && canPlace(startLocX - length, startLocY, grid) == true )
- {
- System.out.print(" Right?");
- canPlace = true;
- }
- }
- else
- {
- System.out.println("The ship you chose cannot be placed here!");
- canPlace = false;
- }
- String ans = " ";
- if(canPlace == true)
- {
- ans = In.getString();
- if(ans.equals("Left"))
- {
- for(int i = length; i > 0; i--) //Dead Code
- {
- grid[startLocX - i][startLocY] = 1;
- return grid;
- }
- }
- else if(ans.equals("Down"))
- {
- for(int i = length; i > 0; i--) //Dead Code
- {
- grid[startLocX][startLocY - i] = 1;
- return grid;
- }
- }
- else if(ans.equals("Right"))
- {
- for(int i = length; i > 0; i--) //Dead Code
- {
- grid[startLocX + i][startLocY] = 1;
- return grid;
- }
- }
- else if(ans.equals("Up"))
- {
- for(int i = length; i > 0; i--) //Dead Code
- {
- grid[startLocX][startLocY + i] = 1;
- return grid;
- }
- }
- }
- else
- {
- return grid;
- }
- return grid;
- }
- public static void main (String[] args)
- {
- //System.out.println( canPlace(6,5) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement