It is currently Tue Dec 10, 2013 8:31 am

 All times are UTC

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: MineSweeper - pressing a 0Posted: Wed Jun 06, 2012 11:49 am
 Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
I have a problem with minesweeper, a game that im making to learn programming basics. The problem is infinite loop. I think I got a code working if there wasn't an error for a endless loop.
So when i press the left button on the mouse it starts a function called GRTRemoveBlocks, this function checks if a value that is loaded when the game starts is 0 (have no mine near).
Code:

void GRTRemoveBlocks(int n) {
if (minenear[n] == 0) {
RemoveBlock(n);
}

if the variable is 0 the game loads the function RemoveBlock.

this is a small example of the code inside:
Code:
void RemoveBlock(int n) {
#region 1-3
if (blockposint[n] == 1) {
IsBlockVisible[n + 1] = false;
IsBlockVisible[n + (int)blockamountxy.Y] = false;
IsBlockVisible[n + (int)blockamountxy.Y + 1] = false;

//this opens the GRTRemoveBlock with different n value
GRTRemoveBlocks(n + 1);
GRTRemoveBlocks(n + (int)blockamountxy.Y);
GRTRemoveBlocks(n + (int)blockamountxy.Y + 1);
}

blockposint is the position of the block
Image to show position:

Top

 Post subject: Re: MineSweeper - pressing a 0Posted: Wed Jun 06, 2012 12:48 pm
 Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1648
Location: burrowed
Mentioning an infinite loop and not pasting the actual loop code doesn't help quite as much

Please try to provide complete code snippets, don't bother if the post gets long, or use services like pastebin or codepaste to paste functions.

Will try to get a look at your code later today.

_________________
Long pork is people!

wzl's burrow

Top

 Post subject: Re: MineSweeper - pressing a 0Posted: Wed Jun 06, 2012 12:58 pm
 Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
weezl wrote:
Mentioning an infinite loop and not pasting the actual loop code doesn't help quite as much

Please try to provide complete code snippets, don't bother if the post gets long, or use services like pastebin or codepaste to paste functions.

Will try to get a look at your code later today.

but that is the loop, when it has set IsBlockVisible[n]= false then it redo the process with 3 other values (checks if it is equal to 0 then remove adjacent blocks) for 3 more blocks. Then it might see that more isn't surrounded with mines So (what i think) the computer thinks it is a infinite loop.

Top

 Post subject: Re: MineSweeper - pressing a 0Posted: Wed Jun 06, 2012 1:14 pm
 Funky Monkey

Joined: Thu Sep 09, 2004 1:17 pm
Posts: 1648
Location: burrowed
oh right, sorry bout that, didn't catch the recursion

Only thing that looks suspicious to me currently is (int)blockamountxy.Y, can you make sure it is not 0?

_________________
Long pork is people!

wzl's burrow

Top

 Post subject: Re: MineSweeper - pressing a 0Posted: Wed Jun 06, 2012 1:50 pm
 Level 1 Cleric

Joined: Thu May 24, 2012 2:33 pm
Posts: 13
weezl wrote:
oh right, sorry bout that, didn't catch the recursion

Only thing that looks suspicious to me currently is (int)blockamountxy.Y, can you make sure it is not 0?

I forgot to say that blockamountxy is a vector that is holding how many blocks there is in a row/column blockamountxy.Y is the Y axis and that is always = 8 in this case. That value is never changed

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 5 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ Forums    Forum Rules and Posting Guidelines Wiki Discussion    Help    Content Issues Game Programming Discussion    C and C++ Game Programming    Java Game Programming    Language Agnostic Programming    .NET Game Programming    VB Game Programming    Mobile Game Programming    Web-Based Game Programming    Other Languages    OpenGL Development    Direct X Development Game Development Discussion    Game Design    Game Media Off-Topic Discussion    Announcements    Off-Topic    Community Projects    News