-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameLauncher.java
More file actions
58 lines (46 loc) · 1.06 KB
/
gameLauncher.java
File metadata and controls
58 lines (46 loc) · 1.06 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
import java.util.Scanner;
public class gameLauncher {
public static void main(String[] args) {
SinkDotCom game = new SinkDotCom();
game.setDotCom();
while(game.dotComAlive()) {
game.userStrike();
}
System.out.println("You win! Total score: " + game.getScore());
}
}
class SinkDotCom {
private int[] field = new int[7];
private int score;
public void setDotCom() {
int startPoint = (int)(Math.random() * 4);
for (int i = 0; i < 7; i++) {
field[i] = 0;
}
for (int i = startPoint; i < startPoint + 3; i++) {
field[i] = 1;
}
}
public boolean dotComAlive() {
for (int i = 0; i < 7; i++) {
if (field[i] == 1) {
return true;
}
}
return false;
}
public void userStrike() {
Scanner reader = new Scanner(System.in);
System.out.print("Enter a number: ");
int n = reader.nextInt();
while (n < 0 || n > 6) {
System.out.print("Enter correct number: ");
n = reader.nextInt();
}
field[n] = 0;
score++;
}
public int getScore() {
return score;
}
}