-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDotComBust.java
90 lines (78 loc) · 2.85 KB
/
DotComBust.java
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
import java.util.ArrayList;
/**
* DotComBust
*/
public class DotComBust {
private GameHelper helper = new GameHelper();
private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();
private int numOfGuesses;
public void setUpGame() {
DotCom one = new DotCom();
one.setName("Pets.com");
DotCom two = new DotCom();
two.setName("eToys.com");
DotCom three = new DotCom();
three.setName("Go2.com");
dotComList.add(one);
dotComList.add(two);
dotComList.add(three);
System.out.println("Your goal is to sink three dot coms.");
System.out.println("Pets.com, eToys.com, Go2.com");
System.out.println("Try to sink them all in the fewest number of guesses");
for (DotCom dotCom : dotComList) {
ArrayList<String> newLoacation = helper.placeDotCom(3);
dotCom.setLocationCells(newLoacation);
}
}
public void startPlaying() {
ArrayList<String> locationCells = new ArrayList<String>();
for (DotCom dotCom : dotComList) {
locationCells.addAll(dotCom.locationCells);
}
ArrayList<String> wrongUserGuesses = new ArrayList<String>();
ArrayList<String> correctUserGuesses = new ArrayList<String>();
while (!dotComList.isEmpty()) {
helper.gridDisplay(correctUserGuesses, wrongUserGuesses);
String userGuess = helper.getUserInput("enter a guess");
if (locationCells.contains(userGuess)) {
correctUserGuesses.add(userGuess);
}
else {
wrongUserGuesses.add(userGuess);
}
checkUserGuess(userGuess);
}
finishGame();
}
public void checkUserGuess(String userGuess) {
numOfGuesses += 1;
String result = "miss";
for (DotCom dotCom : dotComList) {
result = dotCom.checkYourself(userGuess);
if (result.equals("hit")) {
break;
}
if (result == "kill") {
result += " " + dotCom.getName();
dotComList.remove(dotCom);
break;
}
}
System.out.println("Result: " + result);
}
public void finishGame() {
System.out.println("All Dot Coms are dead! Your stock is now worthless.");
if (numOfGuesses <= 18) {
System.out.println("It only took you " + numOfGuesses + " guesses.");
System.out.println("You got out before your options sank.");
} else {
System.out.println("Took you long enough. " + numOfGuesses + " guesses.");
System.out.println("Fish are dancing with your options.");
}
}
public static void main(String[] args) {
DotComBust game = new DotComBust();
game.setUpGame();
game.startPlaying();
}
}