-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpole.java
More file actions
96 lines (72 loc) · 2.12 KB
/
pole.java
File metadata and controls
96 lines (72 loc) · 2.12 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
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class pole extends JPanel{
private Image shapka;
private Image fon;
public int x = 400;
private static int slogn;
private podar[] gamePodar;
private Image end_game;
public Timer timerUpdate;
public Timer timerDraw;
public pole (int slogn) {
this.slogn = slogn;
try {
shapka = ImageIO.read(new File ("C:\\Users\\IArchakov\\workspace\\shapka.png"));
} catch (IOException ex) {}
try {
fon = ImageIO.read(new File ("C:\\Users\\IArchakov\\workspace\\fon.png"));
} catch (IOException ex) {}
try {
end_game = ImageIO.read(new File ("C:\\Users\\IArchakov\\workspace\\end_game.png"));
} catch (IOException ex) {}
gamePodar = new podar[slogn];
for (int i = 0; i < gamePodar.length; i++) {
try {
gamePodar[i] = new podar (ImageIO.read(new File ("C:\\Users\\IArchakov\\workspace\\podar.png")));
} catch (IOException ex) {}
}
timerUpdate = new Timer (3000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
updateStart();
}
});
timerUpdate.start();
timerDraw = new Timer (50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
repaint();
}
});
timerDraw.start();
}
public void paintComponent (Graphics gr) {
super.paintComponent(gr);
gr.drawImage(fon, 0, 0, null);
gr.drawImage(shapka, x, 465, null);
for (int i = 0; i < gamePodar.length; i++) {
gamePodar[i].draw(gr);
if ((gamePodar[i].y + gamePodar[i].img.getHeight(null)) >= 470)
if (Math.abs(gamePodar[i].x - x) > 75) {
gr.drawImage(end_game, 300, 300, null);
timerDraw.stop();
timerUpdate.stop();
break;
}else gamePodar[i].act = false;
}
}
private void updateStart() {
for (int i = 0; i < gamePodar.length; i++) {
if (!gamePodar[i].act) {
gamePodar[i].start();
break;
}
}
}
}