-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleDotComGame.java
More file actions
47 lines (35 loc) · 1.48 KB
/
SimpleDotComGame.java
File metadata and controls
47 lines (35 loc) · 1.48 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
public class SimpleDotComGame {
public static void main(String[] args) {
// Declare integer numOfGuesses variable to store number of player turns
int numOfGuesses = 0;
// Special class to receive user input
GameHelper helper = new GameHelper();
// Create a SimpleDotCom object
SimpleDotCom theDotCom = new SimpleDotCom();
// Calculate random position of the initial cell from 0 to 4
int randomNum = (int) (Math.random() * 5);
// Create an int array with 3 items using the calculated random number increasing it by 1 and then 2
int[] locations = {randomNum, randomNum + 1, randomNum + 2};
// Set location cells
theDotCom.setLocationCells(locations);
// Declare bool isAlive variable to store if the dotCom is still alive
boolean isAlive = true;
// Wile dotCom isAlive
while (isAlive) {
// Get user input
String guess = helper.getUserInput("Inter the number");
// Call checkYourself
String result = theDotCom.checkYourself(guess);
// Increase numOfGuesses
numOfGuesses++;
// Check if the dotCom is sink
if (result.equals("Sink")) {
// If it is:
// Set isAlive to false
isAlive = false;
// Print numOfGuesses
System.out.println("Yo used " + numOfGuesses + " tries!");
}
}
}
}