-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameFrame.java
More file actions
52 lines (44 loc) · 1.16 KB
/
GameFrame.java
File metadata and controls
52 lines (44 loc) · 1.16 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
package ca.bcit.comp2526.a2a;
import java.awt.GridLayout;
import javax.swing.JFrame;
/**
* GameFrame (Window) attached to world.
* @author Kevin Oane, revising editor.
* @version 1.0
*/
public class GameFrame extends JFrame {
/**
* Generated sVUID.
*/
private static final long serialVersionUID = 1623876165767883229L;
private final World world;
/**
* Constructor accepting World object
* for reference.
* @param w
* World.
*/
public GameFrame(final World w) {
world = w;
}
/**
* Initializes GameFrame.
*/
public void init() {
setTitle("Assignment 2a");
setLayout(new GridLayout(world.getRowCount(), world.getColumnCount()));
for (int row = 0; row < world.getRowCount(); row++) {
for (int col = 0; col < world.getColumnCount(); col++) {
add(world.getCellAt(row, col));
}
}
addMouseListener(new TurnListener(this));
}
/**
* Listens for mouse-click.
*/
public void takeTurn() {
world.takeTurn();
repaint();
}
}