-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBulbasaur.java
279 lines (249 loc) · 9.97 KB
/
Bulbasaur.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import java.util.Random;
/**
* Bulbasaur Pokemon object class.
* Dual-type Grass|Poison implements two type interfaces
* Parent class to Ivysaur
* @author Lisa Miller
* @version 1.0
* @since 9/24/2016
*/
public class Bulbasaur extends Pokemon implements GrassType, PoisonType {
/** The minimum attack power for species. */
static final int BASE_ATTACK_POWER = 118;
/** The minimum defense power for species. */
static final int BASE_DEFENSE_POWER = 111;
/** The minimum stamina power for species. */
static final int BASE_STAMINA_POWER = 128;
//booleans for telling which type attack to use for dual type Pokemon
/** Indicator for fast attack type. */
protected boolean fastIsGrass = true;
/** Indicator for special attack type. */
protected boolean specialIsGrass = true;
/**
* Constructor with no name.
* uses Pokemon superclass constructor
* attacks must be set after contruction of Pokemon Object
* because of dependence on type interface
*/
public Bulbasaur() {
super("Bulbasaur", "Bulbasaur", 1, GRASS_COLOR, 0.71, 6.9,
GRASS_TYPE, POISON_TYPE, BASE_ATTACK_POWER,
BASE_DEFENSE_POWER, BASE_STAMINA_POWER);
//pick Attacks after construct
chooseFastAttack();
chooseSpecialAttack();
}
/**
* Constructor with name.
* uses Pokemon superclass constructor
* attacks must be set after contruction of Pokemon Object
* because of dependence on type interface
* @param name The user-defined name.
*/
public Bulbasaur(String name) {
super("Bulbasaur", name, 1, GRASS_COLOR, 0.71, 6.9,
GRASS_TYPE, POISON_TYPE, BASE_ATTACK_POWER,
BASE_DEFENSE_POWER, BASE_STAMINA_POWER);
//pick Attacks
chooseFastAttack();
chooseSpecialAttack();
}
/**
* Constructor with species and name for subclasses.
* This allows subclass specific name, number, height, weight, and basePowers
* to pass through to Pokemon superclass constructor
*@param species The Pokemon's species.
*@param name The optional user-given name.
*@param num The Pokedex number for this species.
*@param ht The height of this Pokemon.
*@param wt The weight of this Pokemon.
*@param baseAttackPwr The low limit of Attack Power for species.
*@param baseDefensePwr The low limit of Defense Power for species.
*@param baseStaminaPwr The low limit of Stamina Power for speices.
*/
protected Bulbasaur(String species, String name, int num,
double ht, double wt, int baseAttackPwr, int baseDefensePwr,
int baseStaminaPwr) {
super(species, name, num, GRASS_COLOR, ht, wt, GRASS_TYPE,
POISON_TYPE, baseAttackPwr, baseDefensePwr, baseStaminaPwr);
//pick Attacks
//can happen here because all subclasses are same types as Bulbasaur
chooseFastAttack();
chooseSpecialAttack();
}
/**
* Grass|Poison-type specific fast attack chooser.
* Randomly picks whether attack type is grass or poison
* Randomly picks an attack from type attack arrays
*/
protected void chooseFastAttack() {
//randomly choose to get grass or poison attack
Random randGen = new Random();
int index;
//set attack type boolean
fastIsGrass = randGen.nextBoolean();
if (fastIsGrass) {
index = randGen.nextInt(GRASS_FAST_ATTACKS.length);
fastAttack = GRASS_FAST_ATTACKS[index];
fastAttackPower = GRASS_FAST_ATK_POWER[index];
} else { //is poison
index = randGen.nextInt(POISON_FAST_ATTACKS.length);
fastAttack = POISON_FAST_ATTACKS[index];
fastAttackPower = POISON_FAST_ATK_POWER[index];
fastIsGrass = false;
}
}
/**
* Grass|Poison-type specific special attack chooser.
* Randomly picks whether attack type is grass or poison
* Randomly picks an attack from type interface attack arrays
*/
protected void chooseSpecialAttack() {
//randomly choose to get grass or poison attack
Random randGen = new Random();
int index;
//set type choice boolean
specialIsGrass = randGen.nextBoolean();
if (specialIsGrass) {
index = randGen.nextInt(GRASS_SPECIAL_ATTACKS.length);
specialAttack = GRASS_SPECIAL_ATTACKS[index];
specialAttackPower = GRASS_SPECIAL_ATK_POWER[index];
} else { //is poison
index = randGen.nextInt(POISON_SPECIAL_ATTACKS.length);
specialAttack = POISON_SPECIAL_ATTACKS[index];
specialAttackPower = POISON_SPECIAL_ATK_POWER[index];
}
}
/**
* Game-play fast attack simulation.
* Creates an output String stating attack details
* checks for weakness/strength adjustment based on
* victim Pokemon's type and attack type
* (only need to check latter for dual-type)
* Calls beAttacked method on attacked victim.
*
* @param victim the Pokemon being attacked
* @return String explaining attack and effectiveness
*/
public String performFastAttack(Pokemon victim) {
Random rand = new Random();
double damage = 0.0;
double modifier = 1.0;
double damageDivisor = 250.0;
String s = "";
String vType = victim.getType1();
//random modifier .85 - 1.00
modifier = (double) (rand.nextInt(16) + 85) / 100.0;
s = name + " performed " + fastAttack + " on " + victim.getSpecies();
//check effectiveness of attack
if (fastIsGrass) { //if attack is grass-type
if (vType.equals("Ground") || vType.equals("Rock")
|| vType.equals("Water")) {
s = s + "\n It was super effective!";
modifier = modifier * 2.0;
} else if (vType.equals("Bug") || vType.equals("Dragon")
|| vType.equals("Fire") || vType.equals("Dragon")
|| vType.equals("Flying") || vType.equals("Grass")
|| vType.equals("Poison") || vType.equals("Steel")) {
s = s + "\n It was not very effective.";
modifier = modifier * 0.5;
}
} else { //is poison attack
if (vType.equals("Grass") || vType.equals("Fairy")) {
s = s + "\n It was super effective!";
modifier = modifier * 2.0;
} else if (vType.equals("Rock") || vType.equals("Ghost")
|| vType.equals("Ground") || vType.equals("Poison")) {
s = s + "\n It was not very effective.";
modifier = modifier * 0.5;
} else if (vType.equals("Steel")) {
s = s + "\n It had no effect.";
modifier = 0;
}
}
//check for same types for bonus
if (type1.equals(vType) && type2.equals(victim.getType2())) {
modifier = modifier * 1.5;
}
//bulbapedia damage formula:
damage = (((2 * level) + 10) / damageDivisor)
* attackPower * (specialAttackPower + 2) * modifier;
//perform hit on victim pokemon
victim.beAttacked((int) damage);
return s;
}
/**
* Game-play special attack simulation.
* Creates an output String stating attack details
* checks for weakness/strength adjustment based on
* victim Pokemon's type and attack type
* (only need to check latter for dual-type)
* uses Damage formula from here:
* http://bulbapedia.bulbagarden.net/wiki/Damage
* Calls beAttacked method on attacked victim.
* @param victim the Pokemon being attacked.
* @return String explaining attack and effectiveness.
*/
public String performSpecialAttack(Pokemon victim) {
Random rand = new Random();
double damage = 0.0;
double modifier = 1.0;
double damageDivisor = 250.0;
String s = "";
String vType = victim.getType1();
//random modifier .85 - 1.00
modifier = (double) (rand.nextInt(16) + 85) / 100.0;
s = name + " performed " + specialAttack + " on " + victim.getSpecies();
//check effectiveness of attack
if (specialIsGrass) { //if attack is grass-type
if (vType.equals("Ground") || vType.equals("Rock")
|| vType.equals("Water")) {
s = s + "\n It was super effective!";
modifier = modifier * 2.0;
} else if (vType.equals("Bug") || vType.equals("Dragon")
|| vType.equals("Fire") || vType.equals("Dragon")
|| vType.equals("Flying") || vType.equals("Grass")
|| vType.equals("Poison") || vType.equals("Steel")) {
s = s + "\n It was not very effective.";
modifier = modifier * 0.5;
}
} else { //is poison attack
if (vType.equals("Grass") || vType.equals("Fairy")) {
s = s + "\n It was super effective!";
modifier = modifier * 2.0;
} else if (vType.equals("Rock") || vType.equals("Ghost")
|| vType.equals("Ground") || vType.equals("Poison")) {
s = s + "\n It was not very effective.";
modifier = modifier * 0.5;
} else if (vType.equals("Steel")) {
s = s + "\n It had no effect.";
modifier = 0; //will zero whole calculation
}
}
//check for same types for bonus
if (type1.equals(vType) && type2.equals(victim.getType2())) {
modifier = modifier * 1.5;
}
//bulbapedia damage formula:
damage = (((2 * level) + 10) / damageDivisor)
* attackPower * (specialAttackPower + 2) * modifier;
//perform hit on victim pokemon
victim.beAttacked((int) damage);
return s;
}
/**
* Reduces Pokemon's HP by damage/defensePower.
* Doesn't allow HP to go less than 0
* Implementation of "fainting" not done here
* @param damage Hit points to take off HP
*/
protected void beAttacked(int damage) {
//part of bulbapedia damage formula
damage = damage / defensePower;
if (hP > damage) {
hP = hP - damage;
} else {
hP = 0; //"Pokemon fainted"
}
}
}