-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathPlayer.java
More file actions
56 lines (47 loc) · 1.27 KB
/
Player.java
File metadata and controls
56 lines (47 loc) · 1.27 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
public class Player
{
// These are the lengths of all of the ships.
private static final int[] SHIP_LENGTHS = {2, 3, 3, 4, 5};
private static final int NUM_OF_SHIPS = 5;
public Ship[] ships;
public Grid playerGrid;
public Grid oppGrid;
public Player()
{
if (NUM_OF_SHIPS != 5) // Num of ships must be 5
{
throw new IllegalArgumentException("ERROR! Num of ships must be 5");
}
ships = new Ship[NUM_OF_SHIPS];
for (int i = 0; i < NUM_OF_SHIPS; i++)
{
Ship tempShip = new Ship(SHIP_LENGTHS[i]);
ships[i] = tempShip;
}
playerGrid = new Grid();
oppGrid = new Grid();
}
public void addShips()
{
for (Ship s: ships)
{
playerGrid.addShip(s);
}
}
public int numOfShipsLeft()
{
int counter = 5;
for (Ship s: ships)
{
if (s.isLocationSet() && s.isDirectionSet())
counter--;
}
return counter;
}
public void chooseShipLocation(Ship s, int row, int col, int direction)
{
s.setLocation(row, col);
s.setDirection(direction);
playerGrid.addShip(s);
}
}