-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trainer.java
51 lines (42 loc) · 1.26 KB
/
Trainer.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
import java.lang.reflect.Constructor;
public class Trainer {
private String name;
private Pokemon[] trainerPokemon;
private int amountOfPokemon;
public Trainer(String _name) {
name = _name;
trainerPokemon = new Pokemon[6];
amountOfPokemon = 0;
}
public void addPokemon(Pokemon pokeAdd) {
if (amountOfPokemon > trainerPokemon.length) {
System.out.println("Trainer cannot hold anymore Pokemon!");
} else {
try {
trainerPokemon[amountOfPokemon] = (Pokemon) pokeAdd.clone();
amountOfPokemon++;
} catch (CloneNotSupportedException e) {
System.out.println("CLONING ERROR");
}
}
}
public String getName() {
return name;
}
public Pokemon getPokemon(int index) {
return trainerPokemon[index];
}
public Pokemon[] getPokeList() {
return trainerPokemon;
}
public void printPokemon() {
System.out.println(name + "'s Current Pokemon");
try {
for (int i = 0; i < trainerPokemon.length; i++) {
System.out.println(trainerPokemon[i].getName());
}
} catch (Exception e) {
// Do nothing
}
}
}