This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Creator.java
409 lines (353 loc) · 15 KB
/
Creator.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package po.crawler.web.project;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class Creator implements Observer {
private JTextField name1;
private JTextField weapon1;
private JTextField boots1;
private JButton upname1;
private JButton downname1;
private JButton upweapon1;
private JButton downweapon1;
private JButton upboots1;
private JButton downboots1;
private JTextField type1;
private JButton warriorbutton1;
private JButton tankbutton1;
private JTextField health1;
private JTextField armor1;
private JTextField force1;
private JTextField witchcraft1;
private JTextField name2;
private JTextField type2;
private JTextField weapon2;
private JTextField boots2;
private JTextField health2;
private JTextField force2;
private JTextField armor2;
private JTextField witchcraft2;
private JButton upname2;
private JButton downname2;
private JButton warriorbutton2;
private JButton tankbutton2;
private JButton upweapon2;
private JButton downweapon2;
private JButton upboots2;
private JButton downboots2;
private JButton magbutton1;
private JButton magbutton2;
private JPanel panel;
private JButton FIGHTButton;
private JLabel label1;
private JLabel img1;
private JLabel img2;
private JTextField result1;
private JTextField result2;
private JButton reset;
private JLabel resultimg1;
private JLabel resultimg2;
private JProgressBar progressBar1;
private Character character1;
private Character character2;
private ImageIcon img_vs = new ImageIcon(this.getClass().getResource("images/vs.jpg"));
private ImageIcon img_battle = new ImageIcon(this.getClass().getResource("images/battle.png"));
private ImageIcon img_winner = new ImageIcon(this.getClass().getResource("images/cup.png"));
private ImageIcon img_loser = new ImageIcon(this.getClass().getResource("images/skull.png"));
private ImageIcon img_work = new ImageIcon(this.getClass().getResource("images/work.png"));
public Creator(Character character1, Character character2){
Image image1 = img_vs.getImage(); // transform it
image1 = image1.getScaledInstance(110, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
img_vs = new ImageIcon(image1); // transform it back
Image image2 = img_battle.getImage(); // transform it
image2 = image2.getScaledInstance(110, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
img_battle = new ImageIcon(image2); // transform it back
Image image3 = img_winner.getImage(); // transform it
image3 = image3.getScaledInstance(110, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
img_winner = new ImageIcon(image3); // transform it back
Image image4 = img_loser.getImage(); // transform it
image4 = image4.getScaledInstance(110, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
img_loser = new ImageIcon(image4); // transform it back
Image image5 = img_work.getImage(); // transform it
image5 = image5.getScaledInstance(110, 110, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way
img_work = new ImageIcon(image5); // transform it back
this.character1=character1;
this.character2=character2;
label1.setIcon(img_vs);
resultimg1.setIcon(img_work);
resultimg2.setIcon(img_work);
name1.setText("CHOOSE CHARACTER");
name2.setText("CHOOSE CHARACTER");
type1.setText("CHOOSE TYPE");
type2.setText("CHOOSE TYPE");
weapon1.setText("CHOOSE WEAPON");
weapon2.setText("CHOOSE WEAPON");
boots1.setText("CHOOSE FOOTGEAR");
boots2.setText("CHOOSE FOOTGEAR");
// BOHATER NR 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
health1.setText(Integer.toString(character1.getHealth()));
armor1.setText(Integer.toString(character1.getArmor()));
witchcraft1.setText(Integer.toString(character1.getWitchcraft()));
force1.setText(Integer.toString(character1.getForce()));
upname1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.changeup();
name1.setText(character1.getName());
}
});
downname1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.changedown();
name1.setText(character1.getName());
}
});
warriorbutton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.warrior();
type1.setText(character1.getType());
refreshfirst();
}
});
magbutton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.mag();
type1.setText(character1.getType());
refreshfirst();
}
});
tankbutton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.tank();
type1.setText(character1.getType());
refreshfirst();
}
});
upweapon1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.item.changeup();
weapon1.setText(character1.item.getName());
refreshfirst();
}
});
downweapon1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.item.changedown();
weapon1.setText(character1.item.getName());
refreshfirst();
}
});
upboots1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.boot.changeup();
boots1.setText(character1.boot.getName());
refreshfirst();
}
});
downboots1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character1.boot.changedown();
boots1.setText(character1.boot.getName());
refreshfirst();
}
});
//BOHATER NR 2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
health2.setText(Integer.toString(character2.getHealth()));
armor2.setText(Integer.toString(character2.getArmor()));
witchcraft2.setText(Integer.toString(character2.getWitchcraft()));
force2.setText(Integer.toString(character2.getForce()));
upname2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.changeup();
name2.setText(character2.getName());
}
});
downname2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.changedown();
name2.setText(character2.getName());
}
});
warriorbutton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.warrior();
type2.setText(character2.getType());
refreshsecond();
}
});
magbutton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.mag();
type2.setText(character2.getType());
refreshsecond();
}
});
tankbutton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.tank();
type2.setText(character2.getType());
health2.setText(Integer.toString(character2.getHealth()));
refreshsecond();
}
});
upweapon2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.item.changeup();
weapon2.setText(character2.item.getName());
refreshsecond();
}
});
downweapon2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.item.changedown();
weapon2.setText(character2.item.getName());
refreshsecond();
}
});
upboots2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.boot.changeup();
boots2.setText(character2.boot.getName());
refreshsecond();
}
});
downboots2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
character2.boot.changedown();
boots2.setText(character2.boot.getName());
refreshsecond();
}
});
FIGHTButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(character1.getName()!="" && character2.getName()!=""){
int sum1 = character1.getHealth() + character1.getForce() + character1.getArmor() + character1.getWitchcraft();
int sum2 = character2.getHealth() + character2.getForce() + character2.getArmor() + character2.getWitchcraft();
label1.setIcon(img_battle);
if(sum1>sum2){
result1.setText("WINNER");
resultimg1.setIcon(img_winner);
result2.setText("LOSER");
resultimg2.setIcon(img_loser);
}
else if(sum1==sum2){
result1.setText("REMIS");
resultimg1.setIcon(img_winner);
result2.setText("REMIS");
resultimg2.setIcon(img_winner);
}
else {
result1.setText("LOSER");
resultimg1.setIcon(img_loser);
result2.setText("WINNER");
resultimg2.setIcon(img_winner);
}
}
}
});
reset.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
result1.setText("");
result2.setText("");
resultimg1.setIcon(img_work);
resultimg2.setIcon(img_work);
character1.reset();
character2.reset();
character1.setName("");
character2.setName("");
name1.setText("CHOOSE CHARACTER");
name2.setText("CHOOSE CHARACTER");
type1.setText("CHOOSE TYPE");
type2.setText("CHOOSE TYPE");
weapon1.setText("CHOOSE WEAPON");
weapon2.setText("CHOOSE WEAPON");
boots1.setText("CHOOSE FOOTGEAR");
boots2.setText("CHOOSE FOOTGEAR");
health1.setText("0");
armor1.setText("0");
witchcraft1.setText("0");
force1.setText("0");
health2.setText("0");
armor2.setText("0");
witchcraft2.setText("0");
force2.setText("0");
label1.setIcon(img_vs);
img1.setIcon(new ImageIcon(this.getClass().getResource("images/trophy.png")));
img1.setText("Postać");
img2.setIcon(new ImageIcon(this.getClass().getResource("images/trophy.png")));
img2.setText("Postać");
}
});
character1.subscribe(this::update);
character2.subscribe(this::update);
}
// Observer update method
public void update() {
if (character1.getPointer()== -1){;}
else{
img1.setIcon(new ImageIcon(this.getClass().getResource((String.format("champions_png/image%d.png",character1.getPointer())))));
img1.setText(GetLOL.characters.get(character1.getPointer()));}
if (character2.getPointer() == -1) {;}
else {
img2.setIcon(new ImageIcon(this.getClass().getResource(String.format("champions_png/image%d.png", character2.getPointer()))));
img2.setText(GetLOL.characters.get(character2.getPointer()));}
}
public static void main(String[] args) {
GetLOL.download(); // pobieram wszystko
Character warrior_one = new Character();
Character warrior_two = new Character();
JFrame frame = new JFrame("battle");
frame.setContentPane(new Creator(warrior_one,warrior_two).panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void refreshfirst() throws NullPointerException{
health1.setText(Integer.toString(character1.getHealth()));
armor1.setText(Integer.toString(character1.getArmor()));
witchcraft1.setText(Integer.toString(character1.getWitchcraft()));
force1.setText(Integer.toString(character1.getForce()));
}
public void refreshsecond() throws NullPointerException{
health2.setText(Integer.toString(character2.getHealth()));
armor2.setText(Integer.toString(character2.getArmor()));
witchcraft2.setText(Integer.toString(character2.getWitchcraft()));
force2.setText(Integer.toString(character2.getForce()));
}
// personalizowane komponenty
private void createUIComponents() {
img1 = new JLabel("postać", new ImageIcon(this.getClass().getResource("images/trophy.png")), JLabel.CENTER);
img1.setVerticalTextPosition(JLabel.TOP);
img1.setHorizontalTextPosition(JLabel.CENTER);
img1.setIconTextGap(4);
img2 = new JLabel("postac", new ImageIcon(this.getClass().getResource("images/trophy.png")), JLabel.CENTER);
img2.setVerticalTextPosition(JLabel.TOP);
img2.setHorizontalTextPosition(JLabel.CENTER);
img2.setIconTextGap(4);
}
}