Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / problem with minesweeper

Author
Message
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 30th Aug 2006 14:48 Edited at: 30th Aug 2006 19:37
ok i'm making a game of minesweeper, and i'm having a problem... you know when you play and the spaces around the mines all have numbers to show how many mines are touching it? this works if i only do left, up and left, up, right (if you know what i mean... like adding a number to the square diagonally up and left if there's a mine there) but as soon as i add the others in some of the numbers aren't where they should be they just disappear...

ok i'm not explaining this very well but anyway here's my code for the main game loop (i have a menu screen before it where you can set the grid width and the number of mines)







the gclicked array values would normally be set to 0 in the game but for the time being they are on 1 so that i can see where the mines and the numbers are being placed



there are quite a lot of pictures used here too, but it isn't a problem with the pictures as they should all show the right numbers because before i started putting in the grids and the arrays i checked that all the pictures i was going to put in were loading into the game properly



EDIT: i really don't know what's going wrong but it's not like it's always messing up in one place or anything... i just looked at a 25x25 grid it generated and there were only half a dozen mines which weren't behaving properly in the whole grid

RIP Dimebag
http://db1games.topcities.com
(used to be demonsbreath)
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Aug 2006 11:55
never mind... its worked fine... i changed the code so it approached it from the other direction... now it goes to a square and sees if there are any mines touching it instead of going to a mine and affecting the squares touching it if you see what i mean





it works now

and I am very happy

RIP Dimebag
http://db1games.topcities.com
(used to be demonsbreath)
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Aug 2006 18:30
hey i'm still making my minesweeper game, but i've run into a couple of other problems.

1. I don't know how to do that thing where when you click on a blank square, loads of squares sometimes open up (unless I do a stupidly long check for each possible place it could be in relation to it but the grid sizes go up to 20x20 so there must be a more efficient way)

2. I don't know how to make it tell when the game is over... it can now tell when you've clicked on a mine, but not when you've marked all the mines correctly and opened up all the other spaces.

3. I don't know how to do that thing which you can do on the windows version where you press the left and right mouse buttons at once and it checks the area around you.


My complete code so far is here, but you can ignore most of it because the first 2 thirds is just the menu...







you can also have a look at the screenshot, download the .exe as it is or download a zip with the code and all the media here if that would help: http://jamesmason01.googlepages.com/index.htm

any other comments, suggestions or tips would also be greatly appreciated.


by the way, I'm only using DBC.

http://jamesmason01.googlepages.com/index.htm
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Sep 2006 10:02
I wrote a version of Minesweeper for the amiga about 10 years ago.
For the clearing part:
Check the square that was clicked
Store each of the eight adjacent squares in a 'check' array.
Check the first square in the array.
Store each of its eight adjacent squares in the check array, unless they are already in it.
Continue until the check array is empty.

As for the game over part:
Store each position in an array that can have three possible values:
0 - still covered, don't know what's beneath it.
1 - Uncovered, either empty or a number.
2 - Flagged.

Now run through the array to check that all squares in the array have a value > 0. If they do then everything is either uncovered or flagged. In which case now you need to check that every square that is flagged has a mine beneath it. If it does then the level is complete.


demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 1st Sep 2006 11:07 Edited at: 1st Sep 2006 15:19
Oh! Clever... I was half way there with both of those but I was just getting confused... I think I see what you mean with the clearing part, but I don't exactly know how to implement it... I'll try a few things though.

The game over part, I should have got that myself. I already have the array with the three possible values and I was going to do that value>0 thing but then I realised that you could have flagged everything and that would still work...


EDIT:




EDIT 2:



I did what you said and made a new array, but I had a few problems because it wanted to update every loop, making it very slow and glitchy, until I figured out that when it was updated I set the value to 2, and only let it update if the value was 0 (it changed it to 1 then checked the grid around it then changed to 2 so that it was not going to be used again)


Now I just have to figure out how to do that left/right click thingy and I'll probably be able to do that it was those other two which I thought would be the problem. Thanks so much for your help

My thoughts so far are...

1. Check the position of the mouse
2. Check to see if both mouse buttons are being pressed
3. Check that the square you're clicking on has been opened up already
4. Check all the squares next to it to see that their gclicked value is set to 0 (this will exclude already opened squares or flagged squares)
5. Check these squares to see that none of them have mines under. I think I'll need another variable for this which can be set to 1 before the checks and if any of them have mines under then it will be returned to 0 but if not then the squares will be opened up and then the value will be returned to 0. I'm not so sure exactly how this bit will work though...


EDIT 3: OK it's finished... if anyone really cares they can download the game or the code with the media from my website, but it's not really worth it...

http://jamesmason01.googlepages.com/index.htm
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Sep 2006 09:03 Edited at: 2nd Sep 2006 09:07
I did a minesweeper game almost 2 years ago, about 160 lines of code.


Each square has a 'state'. By default, they all start at 0.

-1 = opened
0 = unopened
1 = check mark
2 = question mark

Now, when you click, any states above -1 haven't been opened so then do your other stuff.



"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike

Login to post a reply

Server time is: 2024-11-26 11:50:12
Your offset time is: 2024-11-26 11:50:12