Discovery of Objects
When we look over the game drawings and think about what objects our game may need, a few come immediately to mind. There must be some kind of Grid and several Cells. There are different kinds of Cells too.
Cells and a Grid are obvious objects of the game and we'll probably discover other objects as we explore a little. It's perfectly fine to explore and then throw code away if we later learn we're not heading in the right direction.
Exploring with objects is easy to do with Smalltalk and Squeak. I very much enjoy spending time thinking about designs but I've also learned you need to "dive in" sometimes to better understand the objects needed in your design.
As I once heard someone say, "You can read about swimming all you want. But, you'll never learn about swimming until you actually dive in the water."
Of course we believe the water here is safe. The worst we could do is write some code and throw it away. And that's nothing to worry about. You have a backup copy and can easily begin again if needed. Smalltalk development encourages experimentation and quick idea exploration.
The Grid holds our Cells. It also contains the source of our laser beam. Let's go with the idea that the user will "ask" the Grid to fire our laser beam.
There are 3 kinds of Cells.
- Blank, or empty
The basic responsibility of a Cell concerns what happens to the laser beam when it enters the Cell. Also, the Mirror Cells need to know something about their orientation. A Mirror Cells can be thought of as leaning "left" or leaning "right".
If we dig a little deeper into our understanding of these Cells we can imagine that each Cell has 4 internal line-segments. Something like an LED clock. We'll use these segments to indicate the path of the laser beam. Let's explore how that would work with our different Cell types.
The Blank Cell
We label the 4 segments #north, #east, #south, and #west. If the laser beam enters the #west segment then we know the #east segment will light-up. If the laser beam enters #south then the #north segment would also light-up.
The Mirror Cell
Depending on the orientation of the mirror we can also determine the path of the laser beam through the Cell. We identify the corresponding segments using the same technique.
For the "left" leaning Mirror Cell, if the laser beam enters the #west segment we know the #south segment will also light-up. If the laser beam enters the "right" leaning Mirror Cell from the #west it will exit by the #north segment.
The Target Cell
In the case of the Target Cell no other segment will light-up. The laser beam ends its path here.