Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not suggesting this is the only way to do it, but what I would suggest is something like the following. Other people, please feel free to comment on this and make corrections.</p> <ul> <li>Each tile should inherit from something and handle drawing itself. A button seems like the best solution because it already has the button drawing functionality (pressed, unpressed, etc) built in.</li> <li>Each tile should also be aware of its neighbors. You would have eight pointers to each of its eight neighbors, setting them to null of course if there is no neighbor. When it goes to draw, it would query each neighbor's <code>IsMine()</code> function and display the count.</li> <li>If none of its neighbors are a mine, it would then recurse into each neighbor's <code>Reveal()</code> method.</li> <li>For the 7-segment display, each digit is its own class that handles drawing. Then I would make a <code>CountdownSegmentDigit</code> class that inherits from this class, but has additional functionality, namely <code>CountDown()</code>, <code>Set()</code>, and <code>Reset()</code> methods, as well as a <code>HitZero</code> event. Then the display timer itself is a collection of these digits, wired up to propagate zeroes left. Then have a <code>Timer</code> within the timer class which ticks every second and counts down the rightmost digit.</li> <li>When the user clicks, see above. The tile itself will handle the mouse click (it is a button after all) and call its <code>Reveal()</code> method. If it is a mine, it will fire the <code>MineExploded</code> event, which your main form will be listening to.</li> </ul> <p>For me, when I think of how to encapsulate objects, it helps to imagine it as a manufacturing process for physical parts. Ask yourself, "How can I design this system so it can be most efficiently built and reused?" Think about future reuse possibilities too. Remember the assembly process takes small pieces and builds them up into larger and larger pieces until the entire object is built. Each bit should be as independent as possible and handle its own logic, but be able to talk to the outside world when necessary.</p> <p>Take the 7-segment display bit, you could have another use for it later that does not count down. Say you want a speedometer in a car or something. You will already have the digits that you can wire up together. (Think hardware: stock 7-segment displays that do nothing but light up. Then you attach a controller to them and they get functionality.)</p> <p>In fact if you think hard enough, you might find you want <code>CountUp()</code> functionality too. And an event argument in <code>HitZero</code> to tell whether it was by counting up or down. But you can wait until later to add this functionality when you need it. This is where inheritance shines: inherit for your <code>CountDownDigit</code> and make a <code>CountUpOrDownDigit</code>.</p> <p>Thinking about how I might design it in hardware, you might want to design each digit so it knows about its neighbors and count them up or down when appropriate. Have them remember a max value (remember, 60 seconds to a minute, not 100) so when they roll over 0, they reset appropriately. There's a world of possibilites.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload