-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
231 lines (163 loc) · 5.64 KB
/
Event.java
File metadata and controls
231 lines (163 loc) · 5.64 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import java.util.Scanner;
public class Event {
public static void Battle(Character user, Character enemy) {
// BATTLE EVENT!
boolean isCharAlive = true;
boolean isGoblinAlive = true;
do {
// HP BAR
System.out.println("***********************");
System.out.println(user.charName + "'s HP: " + user.charHP);
System.out.println("Enemy's HP: " + enemy.charHP);
System.out.println("***********************");
// Player's turn
Event.YourTurn(user, enemy);
isGoblinAlive = Event.checkAlive(enemy.charHP);
if (isGoblinAlive == false) {
System.out.println("We have a winner!");
System.out.println(user.charName + " is the winner");
System.out.println("");
Event.ExpGain(user, enemy);
break;
}
// Enemy's turn
Event.EnemyTurn(enemy, user);
isCharAlive = Event.checkAlive(user.charHP);
if (isCharAlive == false) {
System.out.println("You fainted...");
break;
}
} while (isCharAlive == true && isGoblinAlive == true);
MatchOver(user, enemy);
}
public static int ChooseAction() {
Scanner in = new Scanner(System.in);
System.out.println("***********************");
System.out.println("What do you want to do?");
System.out.println("1. Attack!");
System.out.println("2. Heal");
System.out.println("***********************");
System.out.println("");
int chosenAction = 0;
try {
chosenAction = in.nextInt();
} catch (Exception e) {
System.out.println("Error during input. Please, input 1 or 2!");
ChooseAction();
}
// if exception happened, makes us choose again
return chosenAction;
}
public static void YourTurn(Character user, Character target) {
int action = ChooseAction();
if (action == 1) {
Roll(user, target);
} else if (action == 2) {
Heal(user);
}
System.out.println("-------------------------");
}
public static void EnemyTurn(Character user, Character target) {
int preRoll = (int) Math.random() * 3 + 1;
if (preRoll == 1 && user.charHP < user.maxHP / 3) {
Heal(user);
} else {
Roll(user, target);
}
}
private static void Roll(Character user, Character target) {
int roll = (int) (Math.random() * 10 + user.luck);
if (roll >= 9) {
CriticalAttack(user, target);
} else if (roll >= 2) {
Attack(user, target);
} else if (roll < 2) {
System.out.println(user.charName + "'s attack missed!");
}
}
private static void Attack(Character user, Character target) {
int damage = (int) ((Math.random() * 20) + user.strength);
System.out.println(user.getName() + " attacked " + target.getName() + " for " + damage);
target.charHP = decreaseHealth(target.charHP, damage);
System.out.println(target.getName() + "'s health is now " + target.getHP());
}
private static void CriticalAttack(Character user, Character target) {
int damage = (int) (((Math.random() * 20) + 15) * 2);
System.out.println("CRITICAL ATTACK!!!!!!!!!!");
System.out.println(user.getName() + " attacked " + target.getName() + " for " + damage);
target.charHP = decreaseHealth(target.charHP, damage);
System.out.println(target.getName() + "'s health is now " + target.getHP());
System.out.println("");
}
private static void Heal(Character user) {
int heal = (int) (Math.random() * 30 + user.intel);
user.charHP += heal;
System.out.println(user.charName + " chooses to heal");
System.out.println("Total heal: " + heal);
if (user.charHP > user.maxHP) {
user.charHP = user.maxHP;
}
}
private static int decreaseHealth(int HP, int damage) {
HP = HP - damage;
if (HP < 0) {
HP = 0;
}
return HP;
}
public static boolean checkAlive(int HP) {
boolean checkAlive = true;
if (HP == 0) {
checkAlive = false;
}
return checkAlive;
}
private static void MatchOver(Character user, Character enemy) {
// HP restoration
System.out.println("HP is restored");
user.charHP = user.maxHP;
System.out.println("Current HP: " + user.charHP);
enemy.charHP = enemy.maxHP;
System.out.println("Current XP: " + user.exp + "/" + (user.level * 50));
}
public static void ExpGain(Character user, Character enemy) {
int expGain = (int) ((Math.random() + enemy.maxHP + 30));
System.out.println("You gained " + expGain + " points of experience");
System.out.println("");
user.exp += expGain;
if (user.exp > user.level * 50) {
LevelUp(user, enemy);
}
}
private static void LevelUp(Character user, Character enemy) {
// USER boost
user.exp = 0;
user.level += 1;
user.maxHP += (int) (Math.random() * 50) + 25;
user.strength += (int) (Math.random() * 15) + 10;
user.intel += (int) (Math.random() * 15) + 10;
user.luck += (int) (Math.random() * 2);
// ENEMY boost
enemy.maxHP += (int) (Math.random() * 100) + 25;
enemy.charHP = enemy.maxHP; // this heals up enemy
enemy.strength += (int) (Math.random() * 15) + 10;
enemy.intel += (int) (Math.random() * 15) + 10;
System.out.println("Level up!!!");
System.out.println("-----------");
System.out.println("Stats");
System.out.println("Max HP: " + user.maxHP);
System.out.println("Strength: " + user.strength);
System.out.println("Intel: " + user.intel);
System.out.println("Luck: " + user.luck);
System.out.println("New level: " + user.level);
}
public static int ChooseOption() {
Scanner in = new Scanner(System.in);
int chosenOption = in.nextInt();
return chosenOption;
}
public static void LeaveGame() {
System.out.println("Leaving the game...");
System.out.println("Disconnected");
}
}