-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerActions.java
More file actions
89 lines (81 loc) · 3.14 KB
/
Copy pathPlayerActions.java
File metadata and controls
89 lines (81 loc) · 3.14 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
import java.util.Scanner;
import java.util.Random;
/**
* This class contains the game actions
* available to the user.
* <p>
* All of them are static and void,
* since they only ever change the internal
* status or print a message.
*/
public final class PlayerActions {
/**
* Asks for the position of a tank and
* reduces its health by five points.
*/
public static final void shootBullet() {
Board.displayNumberedBoardState();
System.out.print("General, what tank shall be shot? ");
int positionToShootAt = new Scanner(System.in).nextInt();
Tank tankToShootAt = Board.getTankFromPosition(positionToShootAt);
try {
tankToShootAt.decreaseHealthByFive();
Board.bulletsFiredCounter++;
} catch (NullPointerException e) {
System.out.println("General, there is clearly not a tank there.");
}
}
/**
* Reduces the health of a random tank to 0,
* skipping tanks whose health is 0.
*/
public static final void activateAtomicBomb() {
/*
* Generates an integer between 0 and (maximum - 1).
* Then adds 1 so the (max) range becomes [1, 4].
*/
while (true) {
// Wendy likes "Kill Bill" starring Uma Thurman
int tokyo = new Random().nextInt(Board.MAX_AMOUNT_OF_TANKS) + 1;
Tank bill = Board.getTankFromPosition(tokyo);
if (bill.health != 0) {
bill.decreaseHealthToZero();
break;
} else {
continue;
}
}
}
/**
* Duplicates the health of the tank with least health,
* skipping tanks whose health is 0.
*/
public static final void activateMutantTank() {
Tank lowestHealthTank = Board.getTankFromPosition(1);
for (int position = 1; position <= Board.MAX_AMOUNT_OF_TANKS; position++) {
if (Board.getTankFromPosition(position).health < lowestHealthTank.health
// Skip "dead tanks" (health equals 0)
&& Board.getTankFromPosition(position).health != 0) {
lowestHealthTank = Board.getTankFromPosition(position);
}
}
lowestHealthTank.health *= 2;
}
/**
* Prints a random grandma quote from her Tank Wars days.
*/
public static final void rememberGrannyWithAQuote() {
String[] grannyQuotes = { "¡Cómo me encanta el dulce aroma de tanque chamuscado!",
"Oh Panzer of the Lake, what is your wisdom?",
"Si tuviera un dólar por cada tanque explotado, tendría como 2000 dólares. O lo que vienen a ser 5 mil pesos…",
"Los aliens, en realidad, son seres que existen.",
"¿Nunca les dije? Casi me premian… ¡pero me robaron mi gloria!" };
System.out.println(grannyQuotes[new Random().nextInt(grannyQuotes.length)]);
}
/**
* Prints a formatted message of the number of bullets/shots fired.
*/
public static final void displayFormattedBulletsFired() {
System.out.println("General, you have fired " + Board.bulletsFiredCounter + " bullets.");
}
}