A mouse problem on my minesweeper project

Hello. I found this site at summer and started to go through the tutorials. I’ve finished lesson 11 now and decided, that now would be a good time to make an event based game.

So I’ve been making a minesweeper clone, because it doesn’t need timers, animations or AI. By this far I’ve made all the logic on the minefield when you click it, and titles appear when clicked, and so on.

Anyways, there’s a problem bothering me now, which I can’t debug on my own.
Whenever you click too furiously around the minefield, the game crashes. It’s okay if you try to open the slots with a very slow speed, it goes on. If you do over 2 clicks per second it crashes. Here’s a part of the code where you do clicking…

Code:

// Let’s try opening a square by clicking
if ( event.type == SDL_MOUSEBUTTONDOWN )
{
if ( event.button.button == SDL_BUTTON_LEFT )
{
// Get the mouse offsets
mouseX = event.button.x;
mouseY = event.button.y;

	// If mouse is inside the playfield
	if ( (mouseX >0) && (mouseY >0) && (mouseX<SCREEN_WIDTH) && (mouseY<SCREEN_HEIGHT) )
	{
		// Open the square
		openX = mouseX/32;
		openY = mouseY/32;
	}
}

}

… and later in the logic …

Code:

if ( (openX >= 0) && (openY >= 0) )
{
if ( map->isVisible( openX, openY ) == INVISIBLE )
{
// If you step on to the mine
if ( map->openSquare( openX, openY ) == true )
{
status = 1;
}
}
}

Please help me, so I can advance and learn more stuff about SDL game developing :slight_smile:

There is no obvious reason why clicking quickly should crash your program.
Have you tried running it in a debugger and finding which line it crashes
on?On 29 September 2010 12:38, Gokotti wrote:

Anyways, there’s a problem bothering me now, which I can’t debug on my own.
Whenever you click too furiously around the minefield, the game crashes.
It’s okay if you try to open the slots with a very slow speed, it goes on.
If you do over 2 clicks per second it crashes. Here’s a part of the code
where you do clicking…

Allright! Found it!
The bug wasn’t in the SDL itself. Minefield array tried to look squares out of indexes, never found them and so it went to a never ending loop…
After I finish this project, I’m never gonna play minesweeper again!

Allright! Found it!
The bug wasn’t in the SDL itself. Minefield array tried to look squares out
of indexes, never found them and so it went to a never ending loop…

Well, that’s the way it is. For every ten lines of code, you have at least
eleven opportunities of getting something non-obviously wrong. :wink:

After I finish this project, I’m never gonna play minesweeper again!

You need to design more addictive games. :slight_smile:

My metric is that if I get bored with the game while developing and testing
it, the game design needs fixing.

That’s a tall order indeed - but aim high and getting halfway there might be
good enough.On Wednesday 03 November 2010, at 10.55.43, “Gokotti” wrote:


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://olofson.net http://olofsonarcade.com http://kobodeluxe.com |
’---------------------------------------------------------------------’