Skip to content

Commit 3032b6f

Browse files
committed
Move flip to Cell
1 parent 561ca41 commit 3032b6f

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎ch15/Cell.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,12 @@ public void turnOn() {
6868
color = ON;
6969
}
7070

71+
public void flip() {
72+
if (isOn()) {
73+
turnOff();
74+
} else {
75+
turnOn();
76+
}
77+
}
78+
7179
}

‎ch15/GridCanvas.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ public Cell getCell(int r, int c) {
6161
*/
6262
public void flip(int r, int c) {
6363
Cell cell = array[r][c];
64-
if (cell.isOff()) {
65-
cell.turnOn();
66-
} else {
67-
cell.turnOff();
68-
}
64+
cell.flip();
6965
}
7066

7167
/**
@@ -119,5 +115,4 @@ public void paint(Graphics g) {
119115
public void update(Graphics g) {
120116
draw(g);
121117
}
122-
123118
}

0 commit comments

Comments
 (0)