|
|
|
@ -6,7 +6,7 @@ |
|
|
|
public class Battleship{ |
|
|
|
public static final int X = 0; |
|
|
|
public static final int Y = 0; |
|
|
|
|
|
|
|
|
|
|
|
private int[][] playerBoard; |
|
|
|
private int[][] computerBoardDisplay; |
|
|
|
private int[][] computerBoardHidden; |
|
|
|
@ -17,19 +17,19 @@ public class Battleship{ |
|
|
|
this.computerBoardDisplay = new int[x][y]; |
|
|
|
this.computerBoardHidden = new int[x][y]; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int[][] getComputerBoardHidden(){ |
|
|
|
return this.computerBoardHidden; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int[][] getComputerBoardDisplay(){ |
|
|
|
return this.computerBoardDisplay; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int[][] getPlayerBoard(){ |
|
|
|
return this.playerBoard; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void randomizingBoard(int[][] board){ |
|
|
|
int[] boundTL = {0,0}; |
|
|
|
int[] boundBR = {board[0].length-1, board.length-1}; |
|
|
|
@ -39,18 +39,18 @@ public class Battleship{ |
|
|
|
3, |
|
|
|
3, |
|
|
|
4, |
|
|
|
5}; |
|
|
|
|
|
|
|
5}; |
|
|
|
|
|
|
|
boolean placed; |
|
|
|
Ship[] ships = new Ship[5]; |
|
|
|
ships[0] = Ship.randomShip(boundTL,boundBR,lengths[0],true); |
|
|
|
for (int i = 1; i < 5; i++){ |
|
|
|
|
|
|
|
|
|
|
|
length = lengths[i]; |
|
|
|
placed = false; |
|
|
|
System.out.println(length); |
|
|
|
while (!placed){ |
|
|
|
|
|
|
|
|
|
|
|
Ship cur_ship = Ship.randomShip(boundTL,boundBR,length,i%2 == 0); |
|
|
|
cur_ship.print(); |
|
|
|
boolean intersects = false; |
|
|
|
@ -79,7 +79,7 @@ public class Battleship{ |
|
|
|
rot += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -90,6 +90,7 @@ public class Battleship{ |
|
|
|
} |
|
|
|
} |
|
|
|
public static void printBoard(int[][] arr){ |
|
|
|
|
|
|
|
for (int row = 0; row < arr.length; row++){ |
|
|
|
String s = ""; |
|
|
|
for (int col = 0; col < arr[row].length; col ++){ |
|
|
|
@ -104,8 +105,11 @@ public class Battleship{ |
|
|
|
} |
|
|
|
public static void main(String[] args){ |
|
|
|
int[][] testBoard = new int[10][10]; |
|
|
|
Ship test = new Ship(new int[] {5,5}, new int[] {9,5}); |
|
|
|
Ship test = new Ship(new int[] {5,5}, new int[] {5,9}); |
|
|
|
int[] stationary = test.getStart().clone(); |
|
|
|
test.print(); |
|
|
|
test.placeOnBoard(testBoard); |
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++){ |
|
|
|
test.print(); |
|
|
|
test.placeOnBoard(testBoard); |
|
|
|
@ -113,5 +117,7 @@ public class Battleship{ |
|
|
|
test.rotate(stationary,1); |
|
|
|
} |
|
|
|
|
|
|
|
//printBoard(testBoard); |
|
|
|
|
|
|
|
} |
|
|
|
} |