Public Group

# Making Minesweeper

This topic is 3656 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've decided that it would be fun to make my own Minesweeper game to improve my programming, so in History today I threw together a quick little loop to randomly spread the mines across the board, but when I tried to tackle the next part, deciding where to put the numbers, I got stuck. It seems rather complex, so if anybody could help me out a bit, just nudge me in the right direction, that would be appreciated. I'm trying to make a flexible way to assign numbers to the squares around the mines that will work with any board size. (I'm assuming somebody's tried to do this before? Is this a pretty common project to undertake at a low level?)

##### Share on other sites
It's pretty simple actually. The number is just the total number of mines in the 8 squares surrounding: x (-1 .. +1) y(-1 .. +1)

So just iterate your 2D array and for each cell that doesn't contain a mine sum up the surrounding mines and assign a number.

-me

##### Share on other sites
Oh, thanks! I hadn't thought about it that way - that's a lot easier than I thought.

##### Share on other sites
A Minesweeper game was one of the first games i made, my method was to simply have a bool array reprisenting the board, true meant there was a mine in that spot, and when a user clicked on a square it counted up the mines around it and assigned a number to the square

##### Share on other sites
And now that I can handle most of the code, that brings me to another problem. I don't really know anything about sprites, graphics, etc. I thought it would make sense to use DirectX 9 to do this project so I can use a window and events, but I don't really know anything about loading in textures in 2D (or 3D for that matter). Are there any good guides online that deal with this?

##### Share on other sites
For a simple MineSweeper game you are probably better using simple GDI graphics. Unless you really want to learn DirectX, it's useless to set everything up and use accelerated 3D for a window game. You can always do it if you want better effects. Vista minesweeper do that I think, but not the XP version.

Also, which language are you using?

##### Share on other sites
I'm programming in C++. I really want to get good with Win32/DirectX stuff, so I figured I might as well use Win32 to do it because I don't know any other languages.

##### Share on other sites
For your first game, i wouldnt suggest going straight into DX, but instead use SDL or something similar, alternatively, there is XNA, however that requres c#

##### Share on other sites
I'd be interested in using SDL, but I know nothing about it really. I downloaded the latest version, but couldn't find a good tutorial on how to (a) install it, (b) set it up with Visual C++ 2008, and (c) use it. Can anybody suggest one, or at least tell me how to get it up and running?

##### Share on other sites
Quote:
 Original post by Barrow BoyI'd be interested in using SDL, but I know nothing about it really. I downloaded the latest version, but couldn't find a good tutorial on how to (a) install it, (b) set it up with Visual C++ 2008, and (c) use it. Can anybody suggest one, or at least tell me how to get it up and running?

Here's a list of SDL resources. Your best bet would be Lazy Foo's tutorials. Have fun!

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
12

• 14
• 22
• 9
• 31
• 18
• ### Forum Statistics

• Total Topics
632618
• Total Posts
3007477
• ### Who's Online (See full list)

There are no registered users currently online

×