Skip to content

Commit 70b0af8

Browse files
committed
cleaned up the code
1 parent 5ed14de commit 70b0af8

5 files changed

Lines changed: 17 additions & 31 deletions

File tree

ch15/Automaton.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* A cellular automaton consists of a grid of cells and has the ability to
3-
* update itself over time.
2+
* A cellular automaton consists of a grid of cells and follows a set of rules
3+
* that update the grid over time.
44
*/
55
public abstract class Automaton {
66

ch15/Cell.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public Cell(int x, int y, int size) {
2929
}
3030

3131
/**
32-
* Paints the cell on the screen.
32+
* Draws the cell on the screen.
3333
*
3434
* @param g graphics context
3535
*/
@@ -41,28 +41,14 @@ public void draw(Graphics g) {
4141
}
4242

4343
/**
44-
* @return the cell's color
45-
*/
46-
public Color getColor() {
47-
return this.color;
48-
}
49-
50-
/**
51-
* @param color the new color
52-
*/
53-
public void setColor(Color color) {
54-
this.color = color;
55-
}
56-
57-
/**
58-
* @return true if the cell is off
44+
* @return true if the cell is OFF
5945
*/
6046
public boolean isOff() {
6147
return this.color == OFF;
6248
}
6349

6450
/**
65-
* @return true if the cell is on
51+
* @return true if the cell is ON
6652
*/
6753
public boolean isOn() {
6854
return this.color == ON;

ch15/Conway.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ private static void updateCell(Cell cell, int count) {
131131
* Simulates one round of Conway's Game of Life.
132132
*/
133133
public void update() {
134-
int rows = grid.getRows();
135-
int cols = grid.getCols();
134+
int rows = grid.numRows();
135+
int cols = grid.numCols();
136136

137137
// count neighbors before changing anything
138138
int[][] counts = new int[rows][cols];

ch15/GridCanvas.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ public GridCanvas(int rows, int cols, int size) {
2626
}
2727
}
2828

29-
// set up the Canvas drawing
29+
// set up the canvas drawing
3030
setSize(cols * size, rows * size);
3131
}
3232

3333
/**
3434
* @return number of rows
3535
*/
36-
public int getRows() {
36+
public int numRows() {
3737
return array.length;
3838
}
3939

4040
/**
4141
* @return number of columns
4242
*/
43-
public int getCols() {
43+
public int numCols() {
4444
return array[0].length;
4545
}
4646

ch15/Simulation.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import javax.swing.JFrame;
33

44
/**
5-
* Application that simulates a zero-player game.
5+
* Application that simulates a cellular automaton.
66
*/
77
public class Simulation {
88

@@ -13,17 +13,17 @@ public class Simulation {
1313
*/
1414
public static void main(String[] args) {
1515

16-
// String title = "Langton's Ant";
17-
// Automaton auto = new Langton();
18-
1916
String title = "Conway's Game of Life";
20-
Automaton auto = new Conway("bakersdozen.cells");
17+
Automaton game = new Conway("bakersdozen.cells");
18+
19+
// String title = "Langton's Ant";
20+
// Automaton game = new Langton();
2121

2222
// set up the window frame
2323
JFrame frame = new JFrame(title);
2424
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2525
frame.setResizable(false);
26-
frame.add(auto.getGrid());
26+
frame.add(game.getGrid());
2727
frame.pack();
2828
frame.setVisible(true);
2929

@@ -33,7 +33,7 @@ public static void main(String[] args) {
3333

3434
// update the drawing
3535
toolkit.sync();
36-
auto.update();
36+
game.update();
3737

3838
// delay the simulation
3939
try {

0 commit comments

Comments
 (0)