-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallSelection.java
More file actions
217 lines (156 loc) · 7.53 KB
/
BallSelection.java
File metadata and controls
217 lines (156 loc) · 7.53 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
import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.awt.*;
public class BallSelection extends JFrame {
private static final long serialVersionUID = 1L;
private ArrayList<Pokemon> bag;
private ArrayList<Ball> balls;
public BallSelection(Pokemon wildPokemon, Pokemon myPokemon, ArrayList<Pokemon> bag, ArrayList<Ball> ball){
super("Select balls");
this.bag = bag;
Container c = getContentPane();
PokePartner p = new PokePartner();
balls = new ArrayList<Ball>();
for(Ball b2 : Bag.ball){
balls.add(b2);
}
//System.out.println(balls);
JPanel head = new JPanel();
JLabel k1 = new JLabel("Select Your Balls ", JLabel.CENTER);
head.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
k1.setFont(k1.getFont().deriveFont(Font.BOLD,35f));
head.setForeground(Color.BLACK);
head.setBackground(Color.YELLOW);
head.add(k1);
JPanel b1 = new JPanel();
b1.setLayout(new BoxLayout(b1, BoxLayout.Y_AXIS));
JPanel button1 = new JPanel();
button1.setLayout(new BoxLayout(button1, BoxLayout.Y_AXIS));
JButton btn = new JButton("Pokeball");
btn.add(Box.createRigidArea(new Dimension(360, 50)));
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(int i = 0 ; i < balls.size() ; ++i ){
if(balls.get(i).getName()=="Pokeball"){
if(balls.get(i).getNumber()!= 0){
p.deleteBall(balls.get(i));
checkWin(wildPokemon, myPokemon, balls.get(i));
setVisible(false);
}
else if(balls.get(i).getNumber() == 0){
new BallSelection( wildPokemon, myPokemon, bag, ball);
}
}
}
}
});
JButton btn2 = new JButton("Quickball");
btn2.add(Box.createRigidArea(new Dimension(360, 50)));
btn2.addActionListener(new ActionListener(){
//anonymous class
public void actionPerformed(ActionEvent e) {
for(int i = 0 ; i < balls.size() ; ++i ){
if(balls.get(i).getName()=="Quickball"){
if(balls.get(i).getNumber()!= 0){
p.deleteBall(balls.get(i));
checkWin(wildPokemon, myPokemon, balls.get(i));
setVisible(false);
}
else if(balls.get(i).getNumber() == 0){
new BallSelection( wildPokemon, myPokemon, bag, ball);
}
}
}
}
});
JPanel button2 = new JPanel();
button2.setLayout(new BoxLayout(button2, BoxLayout.Y_AXIS));
Bag.ball = balls;
System.out.println(balls);
JButton btn3 = new JButton("Timerball");
btn3.add(Box.createRigidArea(new Dimension(360, 50)));
btn3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(int i = 0 ; i < balls.size() ; ++i ){
if(balls.get(i).getName()=="Timerball"){
if(balls.get(i).getNumber()!= 0){
p.deleteBall(balls.get(i));
checkWin(wildPokemon, myPokemon, balls.get(i));
setVisible(false);
}
else if(balls.get(i).getNumber() == 0){
new BallSelection( wildPokemon, myPokemon, bag, ball);
}
}
}
}
});
JButton btn4 = new JButton("Ultraball");
btn4.add(Box.createRigidArea(new Dimension(360, 50)));
btn4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(int i = 0 ; i < balls.size() ; ++i ){
if(balls.get(i).getName()=="Ultraball"){
if(balls.get(i).getNumber()!= 0){
p.deleteBall(balls.get(i));
checkWin(wildPokemon, myPokemon, balls.get(i));
setVisible(false);
}
else if(balls.get(i).getNumber() == 0){
new BallSelection( wildPokemon, myPokemon, bag, ball);
}
}
}
}
});
JPanel button3 = new JPanel();
button3.setLayout(new BoxLayout(button3, BoxLayout.X_AXIS));
button3.setBorder(BorderFactory.createEmptyBorder(10, 140, 10, 10));
JButton btn5 = new JButton("Masterball");
btn5.add(Box.createRigidArea(new Dimension(360, 50)));
btn5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
for(int i = 0 ; i < balls.size() ; ++i ){
if(balls.get(i).getName()=="Masterball"){
if(balls.get(i).getNumber()!= 0){
p.deleteBall(balls.get(i));
checkWin(wildPokemon, myPokemon, balls.get(i));
setVisible(false);
}
else if(balls.get(i).getNumber() == 0){
new BallSelection( wildPokemon, myPokemon, bag, ball);
}
}
}
}
});
Bag.ball = balls;
button1.add(btn);
button1.add(btn2);
button1.add(btn3);
button1.add(btn4);
button1.add(btn5);
c.add(head, BorderLayout.NORTH);
c.add(button1, BorderLayout.CENTER);
setSize(400, 420);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void checkWin(Pokemon wildPokemon,Pokemon myPokemon,Ball b){
int value = ((3*wildPokemon.getMaxHP()) - (2*wildPokemon.getHP())+(3*myPokemon.getMaxHP()) -(2*myPokemon.getHP()) )* b.getRate() * 100 / 10 * (3*wildPokemon.getMaxHP());
if(value > 50 ){
MyPokeName m = new MyPokeName(wildPokemon,bag);
m.playgui(wildPokemon,bag);
int pp = myPokemon.getPP()+3;
myPokemon.setPP(pp);
}
else{
System.out.println("You failed to catch");
JOptionPane.showMessageDialog(null,"You failed to catch");
new BallSelection( wildPokemon, myPokemon, bag, balls);
int pp = myPokemon.getPP()+1;
myPokemon.setPP(pp);
}
}
}