-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.java
More file actions
91 lines (60 loc) · 2.68 KB
/
UserInterface.java
File metadata and controls
91 lines (60 loc) · 2.68 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
// =============================================================================
/**
* The <code>UserInterface</code> for the <i>Game of Life</i>. A
* <code>UserInterface</code> controls the progression from one generation to
* the next, displaying the state at each generation.
**/
// =============================================================================
// =============================================================================
public class UserInterface {
// =============================================================================
// =========================================================================
/**
* The constructor. Hold onto a pointer to the <code>Game</code> for which
* this <code>UserInterface</code> is providing interaction.
*
* @param game The <code>Game</code> whose state to draw.
**/
public UserInterface (Game game) {
_game = game;
} // UserInterface ()
// =========================================================================
// =========================================================================
/**
* Display the state of the <code>Cell</code>s in the <code>Grid</code>.
**/
public void display () {
// Provide generation and population counts.
System.out.println("Generation = " + _game.getGeneration() +
", Population = " + _game.getPopulation());
// Provide a textual representation of the grid of cells themselves.
for (int row = 0; row < _game.getRows(); row++) {
for (int column = 0; column < _game.getColumns(); column++) {
Cell cell = _game.getCell(row, column);
System.out.print(cell);
}
// Move to a new line for the next row.
System.out.println();
}
System.out.println();
} // display ()
// =========================================================================
// =========================================================================
/**
* Keep control of the program until it is time to advance the state of the
* <code>Game</code>.
**/
public void triggerMove () {
// Do nothing. Just let it advance as quickly as it wants.
}
// =========================================================================
// =========================================================================
// DATA MEMBERS
/**
* The <code>Game</code> that this interface is controlling.
**/
Game _game;
// =========================================================================
// =============================================================================
} // class UserInterface
// =============================================================================