forked from ccase/Cowboys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Duel.java
188 lines (145 loc) · 5.32 KB
/
Duel.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import java.util.Scanner;
public class Duel {
Shooter A;
Shooter B;
String hisA = "";
String hisB = "";
int bulletsA = 0;
int bulletsB = 0;
int rounds = 0;
public Duel(Shooter A, Shooter B){
this.A = A;
this.B = B;
}
public String run(boolean show_moves){
int turnCounter = 0;
while(turnCounter++ < 100){
rounds = turnCounter;
String aMove = A.play(hisA, hisB);
String bMove = B.play(hisB, hisA);
hisA = hisA + aMove;
hisB = hisB + bMove;
int printBulletsA = bulletsA + ((aMove.equals("R"))?1:0) - ((aMove.equals("S"))?1:0);
int printBulletsB = bulletsB + ((bMove.equals("R"))?1:0) - ((bMove.equals("S"))?1:0);
if (printBulletsA < 0) {printBulletsA = 0;}
if (printBulletsB < 0) {printBulletsB = 0;}
if (show_moves) {
System.out.print("\u001b[2J");
System.out.flush();
System.out.println("Round " + rounds + "\n");
System.out.println(" " + A.toS() + " ------versus------ " + B.toS() + "\n");
System.out.println("Ammo " + printBulletsA + " " + printBulletsB);
AePlayWave aw;
if (aMove.equals("S") && bMove.equals("S")) {
System.out.print(AsciiArt.ss);
if (bulletsA > 5 && bulletsB > 5) {
aw = new AePlayWave("./sound_effects/richochet.wav" );
} else if (bulletsA > 5 || bulletsB > 5) {
aw = new AePlayWave("./sound_effects/shot.wav" );
} else if (bulletsA > 0 && bulletsB > 0) {
aw = new AePlayWave("./sound_effects/richochet.wav" );
} else if (bulletsA > 0 || bulletsB > 0) {
aw = new AePlayWave("./sound_effects/pain.wav" );
} else {
aw = new AePlayWave("./sound_effects/blank.wav" );
}
}
else if (aMove.equals("S") && bMove.equals("R")) {
System.out.print(AsciiArt.sr);
if (bulletsA > 0) {
aw = new AePlayWave("./sound_effects/pain.wav" );
} else {
aw = new AePlayWave("./sound_effects/blank.wav" );
}
}
else if (aMove.equals("S") && bMove.equals("B")) {
System.out.print(AsciiArt.sb);
if (bulletsA > 5) {
aw = new AePlayWave("./sound_effects/shot.wav" );
} else if (bulletsA > 0) {
aw = new AePlayWave("./sound_effects/richochet.wav" );
} else {
aw = new AePlayWave("./sound_effects/blank.wav" );
}
}
else if (aMove.equals("R") && bMove.equals("S")) {
System.out.print(AsciiArt.rs);
if (bulletsB > 0) {
aw = new AePlayWave("./sound_effects/pain.wav" );
} else {
aw = new AePlayWave("./sound_effects/blank.wav" );
}
}
else if (aMove.equals("R") && bMove.equals("R")) {
System.out.print(AsciiArt.rr);
aw = new AePlayWave("./sound_effects/reload.wav" );
}
else if (aMove.equals("R") && bMove.equals("B")) {
System.out.print(AsciiArt.rb);
aw = new AePlayWave("./sound_effects/reload.wav" );
}
else if (aMove.equals("B") && bMove.equals("S")) {
System.out.print(AsciiArt.bs);
if (bulletsB > 5) {
aw = new AePlayWave("./sound_effects/shot.wav" );
} else if (bulletsB > 0) {
aw = new AePlayWave("./sound_effects/richochet.wav" );
} else {
aw = new AePlayWave("./sound_effects/blank.wav" );
}
}
else if (aMove.equals("B") && bMove.equals("R")) {
System.out.print(AsciiArt.br);
aw = new AePlayWave("./sound_effects/reload.wav" );
}
else {
System.out.print(AsciiArt.bb);
aw = new AePlayWave("./sound_effects/block.wav" );
}
aw.start();
Scanner s = new Scanner(System.in);
s.nextLine();
// try {
// Thread.sleep(1000); //1000 milliseconds is one second.
// } catch(InterruptedException ex) {
// Thread.currentThread().interrupt();
// }
}
if (aMove.equals("S")) {
if (bulletsA > 5) {
if (bMove.equals("S")) {
if (bulletsB > 5) {bulletsA --; bulletsB --;}
else {return "A";}
} else {return "A";}
} else if (bulletsA > 0) {
if (bMove.equals("S")) {
if (bulletsB > 5) {return "B";}
else if (bulletsB > 0) {bulletsA --; bulletsB --;}
else {return "A";}
} else if (bMove.equals("R")) {return "A";}
else {bulletsA --;}
} else {
if (bMove.equals("S")) {
if (bulletsB > 0) {return "B";}
} else if (bMove.equals("R")) {bulletsB ++;}
}
} else if (aMove.equals("R")) {
if (bMove.equals("S")) {
if (bulletsB > 0) {return "B";}
else {bulletsA ++;}
} else if (bMove.equals("R")) {
bulletsA ++;
bulletsB ++;
} else {
bulletsA ++;
}
} else {
if (bMove.equals("S")) {
if (bulletsB > 5) {return "B";}
else if (bulletsB > 0) {bulletsB --;}
} else if (bMove.equals("R")) {bulletsB ++;}
}
}
return "T";
}
}