Computer Science Canada

I need help on minesweeper game

Author:  Frank [ Fri Jun 04, 2004 4:42 pm ]
Post subject:  I need help on minesweeper game

I've done quite a bit. My problem is that I cant get my bombs to stay thier enitial value. I've made a function to place 10 random bombs on the 8 by 8 tile playing field. I placed the bomb function inside my grid function so that they are placed on top off the board but under the tiles. When you click a tile it hides and the square of the board is revealed. If a bomb is there it will show it but when you go to click another tile all the bombs randomize in a new location.

To sum it all up: I need my bombs to stay at thier random spots.

Author:  Tony [ Fri Jun 04, 2004 5:27 pm ]
Post subject: 

that's because you locate your bombs every time you draw your grid... Confused So they end up getting new random values. Drawing bombs and randomly placing them should be separate procedures.

maybe this will give you some ideas

Author:  SuperGenius [ Fri Jun 04, 2004 7:25 pm ]
Post subject: 

just make sure that you declare the random positions outside any loops, so that the randint statements will only be called once per round.

Author:  Frank [ Fri Jun 04, 2004 7:39 pm ]
Post subject:  hmmm

Your help is fine, yes. But I can't just declare the mines outside a loop. Every time you press a GUI.button it hides it and I have to refresh my grid and refresh the rest of the buttons on top of that using GUI.Refresh. In order to keep my bombs there I need to refresh them too but everytime I refresh they go in new random spots. I need to fix it so that the bombslocate procedure is called once and the exact postion of those bombs are refreshed instead of looping the whole procedure again.

I hope you understand what I mean.

Author:  Tony [ Fri Jun 04, 2004 8:00 pm ]
Post subject: 

code:

procedure bomblocate
    for f : 1 .. 10
        randint (ran, 1, 8)
        randint (ran2, 1, 8)
        drawfilloval (ran * 30 - 15, ran2 * 30 - 15, 4, 4, 7)
        bombs (ran, ran2) := 1
    end for
end bomblocate

that's bad Laughing

you see how you just draw a bomb in a random place every time? yeah... don't do that... instead you save the location of the bomb and draw that... kinda like what you're doing now with bombs array... just
code:

for i:1..10
for j:1..10
if bombs(i,j) = 1 then
%draw bomb at (i,j) spot
end if
end for
end for


though obviously there're better ways

Author:  xxxxx [ Wed Jan 23, 2008 8:56 pm ]
Post subject:  RE:I need help on minesweeper game

were do you put that code


: