-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHuman.java
More file actions
74 lines (63 loc) · 1.82 KB
/
Copy pathHuman.java
File metadata and controls
74 lines (63 loc) · 1.82 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
/*================================
class Human -- subclass of Player
================================*/
import cs1.Keyboard;
public class Human extends Player {
//========== Default Constructor ==========//
public Human () {
super();
setBoard();
_battlefield.sprinkle();
}
public Human (String nation) {
this();
_nation = nation;
}
//========= METHODS ==========//
public void attack (Player opp) {
int r, c;
System.out.print("Choose a row: ");
r = Keyboard.readInt();
System.out.print("Choose a column: ");
c = Keyboard.readInt();
hit(opp, r, c);
}
public void setBoard() {
int r, c;
String dir;
int i = 0;
System.out.println(_nation + ", place your ships!" );
System.out.println("You have :");
for (Tile s : ships) {
System.out.println("\t" + s._type);
}
while (i < ships.length) {
System.out.println("Here's your board:");
System.out.println(_battlefield.reveal());
System.out.println("Where do you want to place the " + ships[i]._type + "?");
System.out.print("Choose a row: ");
r = Keyboard.readInt();
System.out.print("Choose a column: ");
c = Keyboard.readInt();
System.out.print("Choose a direction (north, south, east, west): ");
dir = Keyboard.readString();
if (_battlefield.place(r,c,dir, ships[i]))
i++;
else
System.out.println("out of range");
}
}
public static void main (String[] args) {
Player person = new Human("name");
//System.out.println(person);
//person._board[1][2] = new Tile("ship" , 1, "-x-");
person._battlefield.set(1,2,new Tile("ship", 1, "-x-"));
person._battlefield.flip(1,2);
System.out.println("before");
System.out.println(person);
Player opp = new Human();
opp.hit(person, 1, 2);
System.out.println("after");
System.out.println(person);
}
}