|
|
|
@ -32,7 +32,7 @@ public class Battleship{ |
|
|
|
|
|
|
|
public static void randomizingBoard(int[][] board){ |
|
|
|
int[] boundTL = {0,0}; |
|
|
|
int[] boundBR = {board[0].length, board.length}; |
|
|
|
int[] boundBR = {board[0].length-1, board.length-1}; |
|
|
|
int length; |
|
|
|
int[] lengths = { |
|
|
|
2, |
|
|
|
@ -56,7 +56,7 @@ public class Battleship{ |
|
|
|
int[] stationary = cur_ship.getStart().clone(); |
|
|
|
while ((rot < 4) && !placed) { |
|
|
|
// ensures ship doesn't intect with any that were previously placed |
|
|
|
for (int j = 0; j < i + 1; j++){ |
|
|
|
for (int j = 0; j < i; j++){ |
|
|
|
intersects = cur_ship.isIntersecting(ships[j]); |
|
|
|
if (intersects){ |
|
|
|
cur_ship.rotate(stationary,1); |
|
|
|
@ -83,4 +83,27 @@ public class Battleship{ |
|
|
|
ships[i].placeOnBoard(board); |
|
|
|
} |
|
|
|
} |
|
|
|
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 ++){ |
|
|
|
if (arr[row][col] == 4){ |
|
|
|
s += "+"; |
|
|
|
} |
|
|
|
else { |
|
|
|
s += " "; |
|
|
|
} |
|
|
|
if (col < arr[row].length - 1){ |
|
|
|
s += " "; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
System.out.println(s + "\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
public static void main(String[] args){ |
|
|
|
int[][] testBoard = new int[10][10]; |
|
|
|
randomizingBoard(testBoard); |
|
|
|
printBoard(testBoard); |
|
|
|
} |
|
|
|
} |