Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 I need help on minesweeper game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Frank




PostPosted: 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.



finalassignment.t
 Description:
minesweeper

Download
 Filename:  finalassignment.t
 Filesize:  2.23 KB
 Downloaded:  291 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Jun 04, 2004 5:27 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
SuperGenius




PostPosted: Fri Jun 04, 2004 7:25 pm   Post subject: (No 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.
Frank




PostPosted: 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.
Tony




PostPosted: Fri Jun 04, 2004 8:00 pm   Post subject: (No 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
xxxxx




PostPosted: Wed Jan 23, 2008 8:56 pm   Post subject: RE:I need help on minesweeper game

were do you put that code
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: