Thinking about OO programming, an example/question

Soldato
Joined
10 Mar 2006
Posts
3,975
Thinking about how I would implement Minesweeper, when my skills are up to par.

Would a tile be a Class, that you would create instances of to create the area in which to play? You'd presumably have some methods within it to determine at random if it's a mine or a blank tile, to display it's contents when clicked, to determine how many mines are near?

I'm trying to get my head around how you'd practically use classes. What would beyour approach in this case?
 
Also, would you have some kind of class of display controller, that you'd create an instance of? So that would be a means of controlling where the tiles are and where they are created, etc.?
 
Thanks, that makes sense. How about my interpretation of a class of Tiles? Would you also have a Class of 'Score', say, that was an object to keep track of number of moves, score so far, time played, all that jazz?
 
You could have a base tile class that contains standard information to be used by all tiles and then have various tile types inherit this to cover things like mine tiles for example.

You could have a class that contains fields pertaining to the game logic such as score and permitted moves yes.
 
When it comes to OO programming the way I like to imagine it is if you imagine classes as people. Each person has some information ( variables ) and can answer some questions or do some actions ( functions ).

So for the minesweeper map can you imagine a grid of people each with information on the tile they're in and able to do things like set the tile as checked or put a mine in the tile. Personally that's how I would do it. I'd also have an overall TileMap class that controls the creation of the grid of tiles randomly placing however many mines you want. You wouldn't leave the randomness up to each tile as you can never be sure exactly how many mines you'd have at the end.
 
Back
Top Bottom