I’ve been busy working on a program that can solve Minesweeper puzzles (for no other reason than I think it’s fun). When it comes down to the UI, though, I greatly dislike the idea of instantiating over a hundred of the same control, one per cell. Should I create a custom control that handles all of its drawing and input itself? What approach do you guys suggest?
I’m using WPF, and I’m pretty new. Any pointers would be awesome.
Yes a custom control would be a good idea. Also, M-V-VM is a must in a situation like this; it will reduce the complexity of your app greatly.
I’d take a UniformGrid and use Buttons as the squares. You’d have to create a tri-state custom button if you want to add in the “?” intermediate state.
The model for the button would look like
You deal with the model in code rather than the controls. Drop in nine MineSquares into an ObservableCollection on your ViewModel bound to your UniformGrid and you have a 3×3 minesweeper game. Each button handles its own logic. You can hook into the models via the view model to iterate over all squares and determine if everybody has been clicked.