-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrainer.java
144 lines (116 loc) · 4.86 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
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
import java.util.*;
public class Trainer {
private ArrayList<Pokemon> bag;
private ArrayList<Ball> pokeBag; // bag list
private Scanner sc;
protected String name, nickname;
public Trainer(String name){
bag = new ArrayList<Pokemon>();
pokeBag = new ArrayList<Ball>();
bag.add(new Pikachu("Pikachu"));
pokeBag.add(new Pokeball("Pokeball"));
sc = new Scanner(System.in);
this.name = name;
}
public String getName(){
return this.name;
}
public String setNickName(String nickname){
name = nickname;
return name;
}
public void play(){ //play function
String cmd = "";
do{
System.out.print(" Type Command : (show/catch/quit) : "); //start game menu
cmd = sc.nextLine();
if(cmd.equals("show")){
System.out.print(">> Pokemon right now ! <<\nPokemons in your bag \n\n");
showPokemon(bag);
}else if(cmd.equals("catch")){
catchPokemon();
}
}while(!cmd.equals("quit"));
}
public void catchPokemon(){ // catch func.
System.out.println("Catch ! ! ");
ArrayList<Pokemon> pokemons = PokemonRand.getPokemons(5); //call PokemonRandom
ArrayList<Ball> pokeBalls = PokeballRand.getPokemonballs(2);
System.out.println("Pokemon around you");
int no = 0;
for(Pokemon p: pokemons){
System.out.println("No. "+ no +" "+p.getName() + " HP: "+p.getHp()); //print pokemon around player
no++;
}
System.out.println("\nSelect Target"); //select target to fight/catch
no = sc.nextInt();
Pokemon wildPokemon = pokemons.get(no);
System.out.println("\nSelect pokemon in bag: "); //select your own pokemon
showPokemon(bag);
no = sc.nextInt();
Pokemon myPoke = bag.get(no);
System.out.println("\nSelect Pokeball : ");
showPokeball(pokeBag);
no = sc.nextInt();
Ball ballRand = pokeBalls.get(no);
boolean isWin = false;
do{
myPoke.attack(wildPokemon);
if (wildPokemon.getHp() == 0){
isWin = true;
break;
}else{
wildPokemon.attack(myPoke);
if(myPoke.getHp() == 0){
isWin = false;
break;
}
}
}while(true);
if(isWin){
int n = (int)((Math.random() * 4) + 1); //(int)((Math.random() * max-min) + min);
int ans ;
String s="";
if(myPoke.hp > wildPokemon.hp){ //check isWin?catch:wild pokemon escape
System.out.println("You win ! " + " you catch " + wildPokemon.getName());
wildPokemon.name = setNickName(s);
System.out.println("Gacha Restore! choose 1-5");
ans = sc.nextInt();
if(ans == n){ //gacha restore answer correct hpx2 wrong hpx1
System.out.println("Correct! restore x2");
restore(bag);
bag.add(pokemons.get(no));
}else
System.out.println("Wrong");
restore(bag);
bag.add(pokemons.get(no));
}
}else
System.out.println(wildPokemon.getName() + " won ");
}
public void showPokemon(ArrayList<Pokemon> pokemons){ //func for show pokemon name, hp
int num = 0;
for(Pokemon p:bag){
System.out.println("" + num + " " + p +" HP: " +p.getHp());
num++;
}
}
public void showPokeball(ArrayList<Ball> pokeBalls){ //show pokeball in bag
int num = 0;
for(Ball b:pokeBag){
System.out.println("" + num +" " + b);
num++;
}
}
public ArrayList<Pokemon> getBag(){
return bag;
}
public ArrayList<Ball> getBallBag(){
return pokeBag;
}
public void restore(ArrayList<Pokemon> pokemons){ //restore hp
for(Pokemon p:bag){
p.hp = p.getHp()*2;
}
}
}