-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pokemon.java
262 lines (232 loc) · 7.1 KB
/
Pokemon.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
import java.util.Random;
import java.text.*; //imports decimal format
/*
* Abstract parent class for Pokemon species
* develop branch file
* @author Lisa Miller
* @since 9/23/2013
*/
public abstract class Pokemon{
/*** instance variables ***/
protected String species;
protected String name;
protected int number;
protected String color;
protected double height;
protected double weight;
protected String type1;
protected String type2;
//hidden from user, used to calc HP/CP
protected int attackPower;
protected int defensePower;
protected int staminaPower;
protected double level;
//for battling
protected int hP;
protected int cP;
protected String fastAttack;
protected int fastAttackPower;
protected String specialAttack;
protected int specialAttackPower;
//also hidden converts level to multiplier for CP
private double[] cpMultiplier = {0.094, 0.16639787, 0.21573247, 0.25572005, 0.29024988,
0.3210876 , 0.34921268, 0.37523559, 0.39956728, 0.42250001,
0.44310755, 0.46279839, 0.48168495, 0.49985844, 0.51739395,
0.53435433, 0.55079269, 0.56675452, 0.58227891, 0.59740001,
0.61215729, 0.62656713, 0.64065295, 0.65443563, 0.667934 ,
0.68116492, 0.69414365, 0.70688421, 0.71939909, 0.7317 ,
0.73776948, 0.74378943, 0.74976104, 0.75568551, 0.76156384,
0.76739717, 0.7731865 , 0.77893275, 0.78463697, 0.79030001};
/*** constructor **/
public Pokemon(String species, String name, int number, String color, double height, double weight,
String type1,String type2, int baseAttackPower, int baseDefensePower, int baseStaminaPower){
//for initial level
Random randGen = new Random();
//for calc of CP
double cpMult;
//set simple instance variables
this.species = species;
this.name = name;
this.number = number;
this.color = color;
this.height = height;
this.weight = weight;
this.type1 = type1;
this.type2 = type2;
//generate initial level
this.level = (double)randGen.nextInt(30)+1;
//calculate multiplier for stats
cpMult = cpMultiplier[(int)level-1];
//calculate hidden stats attack. defense, stamina power
attackPower =(int)((baseAttackPower + randGen.nextInt(16))*cpMult);
defensePower = (int)((baseDefensePower + randGen.nextInt(16))*cpMult);
staminaPower = (int)((baseStaminaPower + randGen.nextInt(16))*cpMult);
//set Pokemon's HP and CP from attack, defense and stamina
calculateHPAndCP();
//attacks null here, have to be set separately in subclasses due to type
fastAttack = null;
fastAttackPower = 0;
specialAttack = null;
specialAttackPower = 0;
}
/*private method to calculate or update HP and CP
* uses formula from here: https://pokemongo.gamepress.gg/pokemon-stats-advanced
*/
private void calculateHPAndCP(){
//calculate multiplier for stats
double cpMult = cpMultiplier[(int)level-1];
hP = staminaPower;
if(hP<10){
hP = 10;
}
cP = (int)((attackPower * Math.pow(defensePower,0.5) * Math.pow(staminaPower, 0.5) * Math.pow(cpMult,2))/10.0);
//@author Brian hoole...
if(cP<10){
cP = 10;
}
}
/*** public class methods ***/
/*
* Increases Pokemon's level by 1
* Adjusts HP and CP accordingly
*/
public void levelUp(){
level ++;
calculateHPAndCP();
}
/*
* Returns Pokemon information as a formatted String
* @return String representing Pokemon object data
*/
public String toString( ){
DecimalFormat df = new DecimalFormat("000");
String s="";
s = "Species: " + species + "\n";
if(species.compareTo(name) != 0){
s = s + "Name: " + name + "\n";
}
s = s + "Number: " + df.format(number) + "\n";
s = s + "Height: " + height + "\n";
s = s + "Weight: " + weight + "\n";
s = s + "Type: " + type1;
if(this.type2.length() > 0){
s = s + " | " + this.type2;
}
s = s+ "\n";
s = s + "HP: " + hP + "\n";
s = s + "CP: " + cP + "\n";
return s;
}
/* sets Pokemon's user-defined name
* @param String new name
*/
public void setName(String newName){
name = newName;
}
/*** abstract methods required for sub-classes ***/
/*
* Retrieves victim Pokemon's type.
* Determines if the attack is super effective or not effective
* Performs beAttacked on victim
* @param Pokemon victim the Pokemon object being attacked
* @return String "<species> performed <fastAttack>
* + <it <was super, wasn't very, was not> effective>" depending on type
*/
public abstract String performFastAttack(Pokemon victim);
/*
* Retrieves victim Pokemon's type.
* Determines if the attack is super effective or not effective
* Calculates amount of HP to knock off victim
* Performs beAttacked on victim
* @param Pokemon victim the Pokemon object being attacked
* @return String "<species> performed <specialAttack>
* + <it <was super, wasn't very, was not> effective>" depending on type
*/
public abstract String performSpecialAttack(Pokemon victim);
/*** protected abstract methods, for use only within subclasses ***/
/*
* Reduces Pokemon's HP due to attack
* @param int points to reduce HP
*/
protected abstract void beAttacked(int hit);
/*
* Use the type interface lists to set Pokemon
* Fast and Special Attacks
*/
protected abstract void chooseFastAttack();
protected abstract void chooseSpecialAttack();
/** Get Methods **/
/* returns Pokemon species
* @return String
*/
public String getSpecies(){
return species;
}
/* returns Pokemon userdefined name
* @return String
*/
public String getName(){
return name;
}
/* returns Pokemon color
* @return String
*/
public String getColor(){
return color;
}
/* returns Pokemon height
* @return double
*/
public double getHeight(){
return height;
}
/* returns weight
* @return double
*/
public double getWeight(){
return weight;
}
/* returns Pokemon number from Pokedex
* @return int
*/
public int getNumber(){
return number;
}
/* returns Pokemon primary type
* @return String
*/
public String getType1(){
return type1;
}
/* returns Pokemon secondary type
* @return String
* empty if no secondary type
*/
public String getType2(){
return type2;
}
/* returns Pokemon Hit Power
* @return int
*/
public int getHP(){
return hP;
}
/* returns Pokemon Combat Power
* @return int
*/
public int getCP() {
return cP;
}
/* returns fast/simple attack
* @return String
*/
public String getFastAttack(){
return fastAttack;
}
/* returns special attack
* @return String
*/
public String getSpecialAttack(){
return specialAttack;
}
}//Class