Skip to content

Commit 543b43a

Browse files
committed
fixed invisible whack
1 parent c3eb035 commit 543b43a

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

ch16/BlinkingPolygon.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
public class BlinkingPolygon extends RegularPolygon {
88

9-
private boolean drawFlag;
9+
protected boolean visible;
1010
private int count;
1111

1212
/**
@@ -18,24 +18,24 @@ public class BlinkingPolygon extends RegularPolygon {
1818
*/
1919
public BlinkingPolygon(int nsides, int radius, Color color) {
2020
super(nsides, radius, color);
21-
drawFlag = true;
21+
visible = true;
2222
count = 0;
2323
}
2424

2525
@Override
2626
public void draw(Graphics g) {
27-
if (drawFlag) {
27+
if (visible) {
2828
super.draw(g);
2929
}
3030
}
3131

3232
@Override
3333
public void step() {
34-
// toggle drawFlag every 10 steps
34+
// toggle visibility every 10 steps
3535
count++;
3636
if (count == 10) {
3737
count = 0;
38-
drawFlag = !drawFlag;
38+
visible = !visible;
3939
}
4040
}
4141

ch16/Mole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void step() {
3434
*/
3535
public void whack() {
3636
// ignore whack when invisible
37-
if (color == BROWN) {
37+
if (visible) {
3838
color = Color.LIGHT_GRAY;
3939
alive = false;
4040
}

0 commit comments

Comments
 (0)