-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRPG.java
More file actions
68 lines (66 loc) · 2.14 KB
/
RPG.java
File metadata and controls
68 lines (66 loc) · 2.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
package rpg;
import java.util.Scanner;
public class RPG {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Please enter your character's name: ");
String name = input.nextLine();
int classNum = promptForInput("Please choose a class:", "Warrior", "Wizard", "Rogue");
String clas = "";
switch(classNum) {
case 1: {
clas = "Warrior";
} break;
case 2: {
clas = "Wizard";
} break;
case 3: {
clas = "Rogue";
} break;
}
Player p = new Player(name, clas);
int dungeonNum = promptForInput("Which dungeon would you like to run?", "Dungeon0");
switch(dungeonNum) {
case 1: {
Runnable d0 = new Dungeon0(p);
d0.run();
} break;
}
}
public static int promptForInput(String question, String... opt1) {
Scanner input = new Scanner(System.in);
boolean notDone = true;
int j = 0;
while (notDone) {
System.out.println(question);
int i = 1;
for (String s : opt1) {
System.out.println(i + ". " + s);
i++;
}
try {
j = input.nextInt();
if (j > (i - 1) || j < 1) {
System.out.println("Please enter a number between 1 and " + (i - 1));
}
else {
notDone = false;
}
} catch (Exception ex) {
System.out.println("Please enter a number.");
input.next();
}
}
return j;
}
public static void battle(Player p1, Player p2) {
while (p1.getHealth() > 0 && p2.getHealth() > 0) {
p1.attack(p2);
System.out.println("Health: " + p2.getHealth());
if (p2.getHealth() > 0) {
p2.attack(p1);
System.out.println("Health: " + p1.getHealth());
}
}
}
}