Making Minesweeper

Started by
8 comments, last by Drew_Benton 15 years, 7 months ago
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?)
Advertisement
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
Oh, thanks! I hadn't thought about it that way - that's a lot easier than I thought.
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
Game development blog and portfolio: http://gamexcore.co.uk
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?
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?
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.
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#
Game development blog and portfolio: http://gamexcore.co.uk
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?
Quote:Original post by Barrow Boy
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?


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

This topic is closed to new replies.

Advertisement