-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRace.java
More file actions
142 lines (133 loc) · 5.69 KB
/
Race.java
File metadata and controls
142 lines (133 loc) · 5.69 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.util.Random;
import java.io.*;
public class Race {
public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static String[] obstacles = {"rock", "tree", "old lady", "animal", "road closed"};
public static int ChaseObstacles() {
int score = 0;
for (String obst : obstacles){
int check = -1;
if (obst.equals("rock")){
System.out.println("You have enountered a rock. Jump over (0) or go around (1)?");
while (check != 0 && check != 1){
try {
check = Integer.parseInt(br.readLine());
if (check == 0){
System.out.println("Bad decision. You have sprained your ankle.");
score--;
}
else if (check == 1){
System.out.println("Good decision. You passed this obstacle.");
score++;
}
else {
System.out.println("Please enter in either 0 (Jump Over) or 1 (Go Around)");
}
}
catch (IOException e) {
}
catch (Exception y) {
System.out.println("Please enter in an integer value of 0 (Jump Over) or 1 (Go Around)");
}
}
}
else if (obst.equals("tree")){
System.out.println("You have enountered a tree. Climb over (0) or go around (1)?");
while (check != 0 && check != 1){
try {
check = Integer.parseInt(br.readLine());
if (check == 0){
System.out.println("Bad decision. You have fallen and broken a bone.");
score--;
}
else if (check == 1){
System.out.println("Good decision. You passed this obstacle.");
score++;
}
else {
System.out.println("Please enter in either 0 (Climb Over) or 1 (Go Around)");
}
}
catch (IOException e) {
}
catch (Exception y) {
System.out.println("Please enter in an integer value of 0 (Climb Over) or 1 (Go Around)");
}
}
}
else if (obst.equals("old lady")){
System.out.println("You have enountered an old lady. Wait for her to cross (0) or go around (1)?");
while (check != 0 && check != 1){
try {
check = Integer.parseInt(br.readLine());
if (check == 0){
System.out.println("Bad decision. The headless horseman has caught up to you.");
score--;
}
else if (check == 1){
System.out.println("Good decision. You passed this obstacle.");
score++;
}
else {
System.out.println("Please enter in either 0 (Wait) or 1 (Go Around)");
}
}
catch (IOException e) {
}
catch (Exception y) {
System.out.println("Please enter in an integer value of 0 (Wait) or 1 (Go Around)");
}
}
}
else if (obst.equals("animal")){
System.out.println("You have enountered a large animal crossing. Wait for them to cross (0) or go around (1)?");
while (check != 0 && check != 1){
try {
check = Integer.parseInt(br.readLine());
if (check == 0){
System.out.println("Bad decision. The animal has taken its time and the headless horseman has caught up to you.");
score--;
}
else if (check == 1){
System.out.println("Good decision. You passed this obstacle.");
score++;
}
else {
System.out.println("Please enter in either 0 (Wait) or 1 (Go Around)");
}
}
catch (IOException e) {
}
catch (Exception y) {
System.out.println("Please enter in an integer value of 0 (Wait) or 1 (Go Around)");
}
}
}
else {
System.out.println("You have enountered a closed road. Go through anyways (0) or go around (1)?");
while (check != 0 && check != 1){
try {
check = Integer.parseInt(br.readLine());
if (check == 0){
System.out.println("Bad decision. The road was full of potholes on which you sprained an ankle.");
score--;
}
else if (check == 1){
System.out.println("Good decision. You passed this obstacle.");
score++;
}
else {
System.out.println("Please enter in either 0 (Go Through) or 1 (Go Around)");
}
}
catch (IOException e) {
}
catch (Exception y) {
System.out.println("Please enter in an integer value of 0 (Go Through) or 1 (Go Around)");
}
}
}
}
return score;
}
}