You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.1 KiB
91 lines
2.1 KiB
// Carrier = 5
|
|
// Battleship = 4
|
|
// Cruiser = 3
|
|
// Submarine = 3
|
|
// Pilot = 2
|
|
public class Battleship{
|
|
public static final int X = 0;
|
|
public static final int Y = 0;
|
|
|
|
private int[][] playerBoard;
|
|
private int[][] computerBoardDisplay;
|
|
private int[][] computerBoardHidden;
|
|
private static int playerHits;
|
|
private static int ComputerHits;
|
|
public Battleship(int x, int y){
|
|
this.playerBoard = new int[x][y];
|
|
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 main(String[] args){
|
|
int rand = randint(9,10);
|
|
System.out.println(rand);
|
|
}
|
|
public static void randomizingBoard(int[][] board){
|
|
boolean vert = false;
|
|
int length;
|
|
int[] lengths = {
|
|
2,
|
|
3,
|
|
3,
|
|
4,
|
|
5}
|
|
|
|
boolean placed;
|
|
Ship[] ships = new Ship[5];
|
|
|
|
for (int i = 1; i < 5; i++){
|
|
|
|
length = lengths[i]
|
|
placed = false;
|
|
while (!placed){
|
|
int[] start = new int[2];
|
|
|
|
int[] end = start.clone();
|
|
|
|
if vert{
|
|
end[Y] += length-1;
|
|
}
|
|
else {
|
|
end[X] += length-1;
|
|
}
|
|
|
|
Ship cur_ship = new Ship(start,end);
|
|
int rot = 0;
|
|
while ((rot < 4) && !placed) {
|
|
if cur_ship.isInside(board[0].length,board.length) {
|
|
for (int j = 0; j < i + 1; j++){
|
|
placed = !isIntersecting(
|
|
}
|
|
else {
|
|
rot = 4;
|
|
}
|
|
|
|
|
|
}
|
|
// swap starting position each time
|
|
if (vert) {
|
|
vert = false;
|
|
}
|
|
else {
|
|
vert = true
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|