-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEliteFour.java
137 lines (127 loc) · 5.47 KB
/
EliteFour.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
import java.util.Scanner;
import java.util.EnumMap;
import java.util.Map;
import java.util.ArrayList;
public class EliteFour {
static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
final int playerPartySize = 6;
final int opponentPartySize = 3;
final Map<Type, Boolean> battleRooms = generateRooms();
final Map<Pokemon.Item, Integer> myItems = new EnumMap<>(Pokemon.Item.class);
myItems.put(Pokemon.Item.MAX_POTION, 2);
myItems.put(Pokemon.Item.REVIVE, 2);
myItems.put(Pokemon.Item.POTION, 4);
myItems.put(Pokemon.Item.MAX_ELIXIR, 3);
final AePlayWave battleMusic = PokemonBattle.intro(scan, AePlayWave.BATTLE_MUSIC_PETIT_CUP, AePlayWave.PETIT_CUP_BUFFER_SIZE);
PokemonBattle.displayPokemon();
System.out.println("Choose " + playerPartySize + " pokemon.");
final Pokemon[] party = new Pokemon[playerPartySize];
for (int i = 0; i < party.length; i++) {
party[i] = PokemonBattle.askForPokemon(scan);
}
boolean isDefeated = false;
for (int i = 0; i < battleRooms.size() && !isDefeated; i++) {
Type nextRoom = battleMenu(party, myItems, battleRooms, isDefeated);
TrainerAI opponent = new TrainerAI(opponentPartySize, nextRoom);
isDefeated = !TrainerBattle.battle(scan, party, opponent);
}
if (!isDefeated) {
System.out.println("You have beat the elite four. Now you must face the champion! (Enter)");
scan.nextLine();
battleMenu(party, myItems, battleRooms, isDefeated);
}
if (battleMusic != null) {
battleMusic.quit();
}
}
public static Type battleMenu(Pokemon[] party, Map<Pokemon.Item, Integer> myItems, Map<Type, Boolean> battleRooms, Boolean isDefeated) {
System.out.println("Do you want to (0)Heal or (1)Continue");
int choice = TrainerBattle.getIntFromInput(scan, 0, 1);
if (choice == 0) {
healMenu(party, myItems);
}
ArrayList<Type> rooms = new ArrayList<>();
int counter = 0;
for (Type room: battleRooms.keySet()) {
if (!battleRooms.get(room)) {
rooms.add(room);
System.out.print(counter + "|" + room + "| ");
counter++;
}
}
System.out.println();
if (counter == 0) {
TrainerAI champion = new TrainerAI(6, TrainerAI.MAX_DIFFICULTY - 1);
isDefeated = !TrainerBattle.battle(scan, party, champion);
if (!isDefeated) {
System.out.println("Congratulations you won!!! You are the new champion!");
}
return null;
}
else {
System.out.println("Which room do you choose?");
int path = TrainerBattle.getIntFromInput(scan, 0, counter - 1);
System.out.println("You chose " + rooms.get(path));
battleRooms.put(rooms.get(path), true);
return rooms.get(path);
}
}
static void healMenu(Pokemon[] party, Map<Pokemon.Item, Integer> myItems) {
ArrayList<Pokemon.Item> items = new ArrayList<>();
for (Pokemon.Item i : myItems.keySet()) {
items.add(i);
}
boolean chooseItem = true;
while (chooseItem) {
int counter = 0;
System.out.print("Choose item: ");
for (Pokemon.Item i : myItems.keySet()) {
System.out.print(counter + "|" + i.toString() + " x" + myItems.get(i) + "| ");
counter++;
}
System.out.print(counter + "|GO BACK|");
System.out.println();
int itemIndex = TrainerBattle.getIntFromInput(scan, 0, counter);
if (itemIndex != counter && myItems.get(items.get(itemIndex)) == 0) {
System.out.println("There are no more " + items.get(itemIndex) + "s to use.");
}
else {
if (itemIndex < counter) {
System.out.println("Which Pokemon Do You Heal\n");
for (int i = 0; i < party.length; i++) {
System.out.println("|" + i + "|" + party[i]);
}
Pokemon.Item item = items.get(itemIndex);
int selectMon = TrainerBattle.getIntFromInput(scan, 0, party.length);
if(selectMon == party.length) {
System.out.println("Item use cancelled!\n");
healMenu(party, myItems);
break;
}
Pokemon mon = party[selectMon];
boolean useItem = item.use(mon);
if (useItem) {
myItems.put(items.get(itemIndex), myItems.get(items.get(itemIndex)) - 1);
}
}
else {
chooseItem = false;
}
System.out.println();
}
}
}
public static Map<Type, Boolean> generateRooms() {
Map<Type, Boolean> battleRooms = new EnumMap<>(Type.class);
for (int i = 0; i < 4; i++) {
Type type;
do {
int ran = (int)(Math.random() * Type.values().length);
type = Type.values()[ran];
} while (battleRooms.containsKey(type) || (type == Type.NONE));
battleRooms.put(type, false);
}
return battleRooms;
}
}