Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c32030b

Browse filesBrowse files
committed
minor changes based on narrative
1 parent 543b43a commit c32030b
Copy full SHA for c32030b

File tree

Expand file treeCollapse file tree

4 files changed

+28
-22
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+28
-22
lines changed
Open diff view settings
Collapse file

‎ch15/Cell.java‎

Copy file name to clipboardExpand all lines: ch15/Cell.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Cell(int x, int y, int size) {
3434
* @param g graphics context
3535
*/
3636
public void draw(Graphics g) {
37-
g.setColor(color);
37+
g.setColor(this.color);
3838
g.fillRect(x + 1, y + 1, size - 1, size - 1);
3939
g.setColor(Color.LIGHT_GRAY);
4040
g.drawRect(x, y, size, size);
Collapse file

‎ch15/GridCanvas.java‎

Copy file name to clipboardExpand all lines: ch15/GridCanvas.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public int test(int r, int c) {
7878
if (array[r][c].isOn()) {
7979
return 1;
8080
}
81-
} catch (IndexOutOfBoundsException e) {
81+
} catch (ArrayIndexOutOfBoundsException e) {
8282
// cell doesn't exist
8383
}
8484
return 0;
Collapse file

‎ch15/Langton.java‎

Copy file name to clipboardExpand all lines: ch15/Langton.java
+15-20Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,25 @@ public Langton(int rows, int cols) {
2626
public void update() {
2727

2828
Cell cell = grid.cellAt(xpos, ypos);
29-
if (cell.isOn()) {
30-
// at a black square; flip color and turn left
31-
cell.turnOff();
32-
head = (head + 3) % 4;
33-
} else {
34-
// at a white square; flip color and turn right
35-
cell.turnOn();
29+
if (cell.isOff()) {
30+
// at a white square; turn right and flip color
3631
head = (head + 1) % 4;
32+
cell.turnOn();
33+
} else {
34+
// at a black square; turn left and flip color
35+
head = (head + 3) % 4;
36+
cell.turnOff();
3737
}
3838

3939
// move forward one unit
40-
switch (head) {
41-
case 0:
42-
ypos -= 1;
43-
break;
44-
case 1:
45-
xpos += 1;
46-
break;
47-
case 2:
48-
ypos += 1;
49-
break;
50-
case 3:
51-
xpos -= 1;
52-
break;
40+
if (head == 0) {
41+
ypos -= 1;
42+
} else if (head == 1) {
43+
xpos += 1;
44+
} else if (head == 2) {
45+
ypos += 1;
46+
} else {
47+
xpos -= 1;
5348
}
5449

5550
// TODO: draw a triangle to show the ant
Collapse file

‎ch15/empty.cells‎

Copy file name to clipboard
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!An empty 10x10 grid
2+
..........
3+
..........
4+
..........
5+
..........
6+
..........
7+
..........
8+
..........
9+
..........
10+
..........
11+
..........

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.