-
Notifications
You must be signed in to change notification settings - Fork 0
/
Match.java
114 lines (94 loc) · 2.43 KB
/
Match.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
/**
* íÁÔÞ - óÅÁÎÓ ÉÇÒÙ.
**/
import java.awt.Frame;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
class Match {
private Frame _top;
private PuckSupply _ps;
private BrickPile _bp;
private PlayField _pf;
private MediaTracker _tracker;
private Image[] _lib;
private String _message = "";
public Match() {
_top = new Frame("Bricks");
_pf = new PlayField(this);
_tracker = new MediaTracker(_pf);
_lib = new Image[3];
_lib[0] = _pf.getToolkit().getImage("puck.gif");
_lib[1] = _pf.getToolkit().getImage("puddle.gif");
_lib[2] = _pf.getToolkit().getImage("brick.gif");
_tracker.addImage(_lib[0], 0);
_tracker.addImage(_lib[1], 0);
_tracker.addImage(_lib[2], 0);
MenuBar mbar = new MenuBar();
_top.setMenuBar(mbar);
Menu file = new Menu("Game");
MenuItem i1, i2, i3, i4;
file.add(i1 = new MenuItem("start"));
file.add(i2 = new MenuItem("pause"));
file.add(i3 = new MenuItem("resume"));
file.add(i4 = new MenuItem("exit"));
mbar.add(file);
_top.setSize(600, 400);
i1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
start();
}
});
i2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_pf.stop();
}
});
i3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
_pf.start();
}
});
i4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
_top.add("Center", _pf);
_top.show();
}
public void start() {
try {
_tracker.waitForID(0);
} catch (InterruptedException e) {
return;
}
_message = "";
_pf.clean();
_bp = new BrickPile(_pf, _lib[2]);
_ps = new PuckSupply(3, _pf, _lib[0]);
_pf.addSprite(new Puddle(_pf,_lib[1]));
_pf.addSprite(_ps.get());
_pf.start();
}
public void loose() {
_message = "You Loose";
_pf.repaint();
_pf.stop();
}
public void win() {
_message = "You win";
_pf.repaint();
_pf.stop();
}
public static void main(String[] args) {
Match m = new Match();
}
public String getMessage() {
return _message;
}
}