-
Notifications
You must be signed in to change notification settings - Fork 2
/
BattlehauzCLI.java
170 lines (162 loc) · 11.5 KB
/
BattlehauzCLI.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
package views;
import controllers.GameController;
import controllers.InputException;
import models.items.ConsumableOffensiveItem;
import models.utilities.WordsHelper;
import java.util.Scanner;
public class BattlehauzCLI {
private static final Scanner INPUT = new Scanner(System.in);
public static void displayStartUp(){
System.out.println("""
Welcome to
.----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------. .----------------.\s
| .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | .--------------. | | .--------------. | .--------------. | .--------------. | .--------------. |
| | ______ | | | __ | | | _________ | | | _________ | | | _____ | | | _________ | | | | ____ ____ | | | __ | | | _____ _____ | | | ________ | |
| | |_ _ \\ | | | / \\ | | | | _ _ | | | | | _ _ | | | | |_ _| | | | |_ ___ | | | | | |_ || _| | | | / \\ | | ||_ _||_ _|| | | | __ _| | |
| | | |_) | | | | / /\\ \\ | | | |_/ | | \\_| | | | |_/ | | \\_| | | | | | | | | | |_ \\_| | | | | | |__| | | | | / /\\ \\ | | | | | | | | | | |_/ / / | |
| | | __'. | | | / ____ \\ | | | | | | | | | | | | | | | _ | | | | _| _ | | | | | __ | | | | / ____ \\ | | | | ' ' | | | | .'.' _ | |
| | _| |__) | | | | _/ / \\ \\_ | | | _| |_ | | | _| |_ | | | _| |__/ | | | | _| |___/ | | | | | _| | | |_ | | | _/ / \\ \\_ | | | \\ `--' / | | | _/ /__/ | | |
| | |_______/ | | ||____| |____|| | | |_____| | | | |_____| | | | |________| | | | |_________| | | | | |____||____| | | ||____| |____|| | | `.__.' | | | |________| | |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
| '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | '--------------' | | '--------------' | '--------------' | '--------------' | '--------------' |
'----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------' '----------------'\s""");
}
private static char proceed(){
try {
Scanner proceedScanner = new Scanner(System.in);
System.out.println("\nHow would you like to proceed?");
System.out.println("""
B - Enter BattleHauz
S - Enter the shop
F - View Full Stats
A - About Game
Q - Quit game
""");
System.out.print("> ");
String choiceS = proceedScanner.nextLine();
return choiceS.toUpperCase().charAt(0);
}
catch(StringIndexOutOfBoundsException e){
System.err.println("Oops! Please enter a choice.");
return proceed();
}
}
public static void main(String [] args){
GameController game = new GameController();
displayStartUp();
System.out.print("What should we call you? ");
String name = INPUT.nextLine();
System.out.println(game.start(name));
char choice;
do{
choice = proceed();
try {
switch (choice) {
case 'B' -> {
game.getGamePlayer().addItem(new ConsumableOffensiveItem("Jimmy John's hot stick", 7, 7, 0.07));
game.getGamePlayer().addItem(new ConsumableOffensiveItem("Jimmy John's hot stick", 7, 7, 0.07));
game.getGamePlayer().addItem(new ConsumableOffensiveItem("Jimmy John's hot stick", 7, 7, 0.07));
WordsHelper.rollingTextPrint("Ah, so you have chosen to enter the Battlehauz! Good luck! Oh wait, you don't need luck, you need skill. Good skill!");
System.out.println(game.displayRules());
//Game starts and continues while player is alive
while (game.playerIsAlive()) {
game.enterBattleFloor(); //generate enemies for floor
WordsHelper.rollingTextPrint("\nYou have entered floor " + game.getCurrentFloor() + " of the Battlehauz.");
while (game.hasMoreEnemies() && game.playerIsAlive()) { //while the floor still has enemies
WordsHelper.rollingTextPrint(game.startBattle()); //game.startBattle sets the currentEnemy as the first enemy in the list
System.out.println();
WordsHelper.rollingTextPrint(game.enemyTalk('B'));
while (game.currentEnemyIsAlive() && game.playerIsAlive()) { //while the currentEnemy is still alive
System.out.println(game.displayerCurrentFightersStatus() + "\n");
do {
System.out.println("What would you like to do?");
System.out.println(game.displayPlayerOptions()+"\n");
System.out.print("> ");
String actionChoiceS = INPUT.next();
System.out.println();
try {
int actionChoice = Integer.parseInt(actionChoiceS);
if (actionChoice <= 0 || actionChoice > 2) throw new InputException("");
//Adding some dummy items will remove later
switch (actionChoice) {
case 1 -> {
System.out.println("Which move would you like to select?");
System.out.println(game.displayPlayerMoves());
System.out.print("> ");
String moveChoiceS = INPUT.next();
try {
int moveChoice = Integer.parseInt(moveChoiceS);
if (moveChoice < 0 || moveChoice > game.getGamePlayer().getMoves().size())
throw new InputException("That move doesn't exist! Pick a valid move index!");
System.out.println(game.doPlayerTurn(moveChoice));
System.out.println(game.displayEnemyStatus());
} catch (NumberFormatException | IndexOutOfBoundsException e) {
System.err.println("Oops! Please enter a valid move index.");
} catch (InputException e) {
System.err.println(e.getMessage());
}
}
case 2 -> {
System.out.println(game.displayPlayerInventory());
if (!game.displayPlayerInventory().equals("You have no items you can use!")) {
try {
System.out.print("Which item would you like to use > ");
String itemChoiceS = INPUT.next();
int itemChoice = Integer.parseInt(itemChoiceS);
if (itemChoice < 0 || itemChoice > game.getGamePlayer().getOwnedItemNames().size())
throw new InputException("That item doesn't exist! Pick a valid item index!");
System.out.println(game.playerUseItem(itemChoice));
} catch (NumberFormatException e) {
System.err.println("Oops! Please enter a valid number.");
} catch (InputException e) {
System.err.println(e.getMessage());
}
}
}
}
} catch (NumberFormatException e) {
System.err.println("Oops! Please enter a valid number.");
} catch (InputException e) {
System.err.println("That action doesn't exist! Pick a valid action index!");
}
} while (game.isPlayersTurn());
if (game.currentEnemyIsAlive()) {
WordsHelper.rollingTextPrint(game.doEnemyTurn());
System.out.println();
}
else{
WordsHelper.rollingTextPrint(game.enemyLoss());
}
}
} // game.hasMoreEnemies, completing floor
if (game.playerIsAlive()) game.nextFloor();
}
game.restorePlayerHealth();
}
case 'S' -> {
// TODO: enter shop
}
case 'F' -> displayStats(game);
case 'A' -> displayCredits(game);
case 'Q' -> quit(game);
default -> throw new InputException("Oops! Please enter a valid choice.");
}
}
catch (InputException e){
System.err.println(e.getMessage());
}// end-catch
}while (choice != 'Q'); // do-while
}// main()
private static void displayCredits(GameController game){
System.out.println(game.credits());
}
private static void displayStats(GameController game){
System.out.println(game.displayStats());
}
private static void quit(GameController game){
displayStats(game);
displayCredits(game);
System.out.println("\nThank you for playing Battlehauz! :D");
System.exit(0);
}
}