-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShip.java
More file actions
36 lines (27 loc) · 708 Bytes
/
Copy pathShip.java
File metadata and controls
36 lines (27 loc) · 708 Bytes
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
import java.util.*;
public class Ship {
private ArrayList<String> locationCells;
private String name;
void setName(String name){
this.name = name;
}
String getName(){
return this.name;
}
void setLocationCells(ArrayList<String> loc){
locationCells = loc;
}
public String checkYourself(String userInput) { //accept user input (eg A3, B5 etc)
String result = "miss";
int index = locationCells.indexOf(userInput);
if(index >= 0){
locationCells.remove(index); //if user input is guessed then first remove it from the list
if(locationCells.isEmpty()){ //if list empty this was killing blow!
result = "kill";
} else {
result = "hit";
}
}
return result;
}
}