-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMine.java
More file actions
122 lines (91 loc) · 3.53 KB
/
Mine.java
File metadata and controls
122 lines (91 loc) · 3.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
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class Mine extends JFrame {
private static final long serialVersionUID = 1L;
private JLabel jLabel1;
public JTextField txtName;
private JButton btnClick;
private String no;
private Pokemon wildPokemon;
private ArrayList<Pokemon> bag;
public Mine(Pokemon wildPokemon,ArrayList<Pokemon> bags, ArrayList<Ball> ball){
super("Enter Your Pokemon number");
jLabel1 = new JLabel();
txtName = new JTextField();
btnClick = new JButton();
this.wildPokemon = wildPokemon;
bag = new ArrayList<Pokemon>();
for(Pokemon b : bags){
bag.add(b);
}
System.out.println(bag);
//setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setText("My Pokemon Number");
getContentPane().add(jLabel1);
jLabel1.setBounds(150, 60, 140, 18);
txtName.setName("txtName"); // NOI18N
txtName.setSize(180, 150);
getContentPane().add(txtName);
txtName.setBounds(80, 100, 260, 20);
btnClick.setText("Click");
btnClick.addActionListener(new ActionListener(){
//anonymous class
public void actionPerformed(ActionEvent e) {
btnClickActionPerformed(e);
setVisible(false);
}
});
getContentPane().add(btnClick);
btnClick.setBounds(160, 140, 90, 23);
}
private void btnClickActionPerformed(ActionEvent evt) {
try {
no = txtName.getText();
int result = Integer.parseInt(no);
for(int i = 0; i < bag.size() ; i++){
if(result == i){
Pokemon myPokemon = bag.get(i);
win(wildPokemon, myPokemon, null);
System.out.println(bag);
}
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "ErrorMsg","Please Enter Number", JOptionPane.ERROR_MESSAGE);
}
}
public void win(Pokemon wildPokemon,Pokemon myPokemon,ArrayList<Ball> ball){
boolean isWin = false;
do{
myPokemon.attack(wildPokemon);
if(wildPokemon.getHP() == 0){
System.out.println(wildPokemon.getHP());
isWin = true;
break;
}
wildPokemon.attack(myPokemon);
if(myPokemon.getHP() == 0){
System.out.println(myPokemon.getHP());
isWin = false;
break;
}
}while(true);
if(isWin){
PersonalTrainer.bag = bag;
System.out.println(bag);
JOptionPane.showMessageDialog(null,"You Win");
new BallSelection(wildPokemon,myPokemon,bag,ball);
}
else{
System.out.println(wildPokemon.getName() + " win");
}
}
public void playgui(Pokemon wildPokemon,ArrayList<Pokemon> bags, ArrayList<Ball> ball) {
Mine frame = new Mine(wildPokemon,bags,ball);
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setResizable(false);
}
}