Go back to the LaserGame and fill-in the #newGame method now.
self grid initializeCells.
self grid stopLaser.
self moves: 0.
self activeCellLocation: nil.
GridFactory randomizeGrid: self grid.
We still have to complete our refactoring here. Here's the modified #fireLaser code.
ifTrue: [self grid stopLaser]
ifFalse: [self grid fireLaser].
With the possibility of a grid being randomized with the new button, we have to ensure that old cells are properly repainting now. Before we relied on the fact that the cells were all initially blank. Now it's possible for a cell to change from a blank to being a mirror, or from a mirror to being blank, and the orientation of a mirror can change. We need better cleanup and redraw code. Here's a new instance method on CellRenderer.
| offset backgroundRect |
offset := self offsetWithinGridForm.
backgroundRect := offset extent: CellRenderer cellExtent - 2.
self targetForm fill: backgroundRect fillColor: LaserGameColors gameBoardBackgroundColor.
The #redrawCell method needs to change.
The blank cell should ensure that it's really blank...
The mirror cell should repaint its background too now.
self cell isLeft
ifTrue: [self renderContentsLeanLeft]
ifFalse: [self renderContentsLeanRight]
And the target cell.
self cell isOn
ifTrue: [self renderContentsOn]
ifFalse: [self renderContentsOff]
Okay, that should do it. Open up a new LaserGame morph. Move some mirror cells around, rotate others. Then try the new game button and everything should be correct.
Once again we should save our package with Monticello. Save as version 6.