-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
118 lines (109 loc) · 2.39 KB
/
Copy pathPlayer.java
File metadata and controls
118 lines (109 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import java.util.Random;
import java.util.Scanner;
import BoatTypes.AircraftCarrier;
import BoatTypes.Battleship;
import BoatTypes.Boats;
import BoatTypes.Cruiser;
import BoatTypes.Destroyer;
import BoatTypes.Submarine;
public class Player
{
Boats[] boats = new Boats[10];
Board board;
Board enemyBoard;
int boardSize;
int boatsAlive = 10;
public Player(int size)
{
board = new Board(size);
enemyBoard = new Board(size);
boats[0] = new AircraftCarrier();
boats[1] = new Battleship();
boats[2] = new Battleship();
boats[3] = new Cruiser();
boats[4] = new Cruiser();
boats[5] = new Destroyer();
boats[6] = new Destroyer();
boats[7] = new Submarine();
boats[8] = new Submarine();
boats[9] = new Submarine();
this.boardSize = size;
}
public void killBoat()
{
boatsAlive--;
if (boatsAlive <= 0)
{
System.out.println("GAME OVER!");
System.exit(0);
}
}
public void setBoard()
{
for(int i = 0; i < boats.length; i++)
{
boolean condicao = true;
while (condicao)
{
System.out.println("Setting boat: " + boats[i].getName());
System.out.println("Enter number of row: ");
Scanner in = new Scanner(System.in);
int row = in.nextInt();
System.out.println("Enter number of Col");
int col = in.nextInt();
System.out.println("Is the boat on vertical? y/n");
String vertical = in.next();
boolean isVertical = false;
if (vertical.equals("y"))
{
isVertical = true;
}
boats[i].setBoatVar(row, col, isVertical);
if (board.isValidPlay(boats[i]))
{
board.setBoat(boats[i]);
board.printBoard();
condicao = false;
}
else
{
System.out.println("Ilegal Position, try again");
}
}
}
}
public void setRandomBoard()
{
for (int i = 0; i < boats.length; i++)
{
boolean condicao = true;
while (condicao)
{
Random random = new Random();
int x = random.nextInt(boardSize);
int y = random.nextInt(boardSize);
boolean vertical = random.nextBoolean();
boats[i].setBoatVar(x, y,vertical);
if(board.isValidPlay(boats[i]))
{
board.setBoat(boats[i]);
//board.printBoard();
condicao = false;
}
}
}
}
public Boats getBoat(int row, int col)
{
Boats boatFound = null;
for (int i = 0; i < boats.length; i++)
{
if (boats[i].isHere(row, col))
{
boatFound = boats[i];
break;
}
}
return boatFound;
}
}