Computer Science Canada Need help for my minesweeper game |
Author: | Johnny19931993 [ Wed Mar 18, 2009 4:43 pm ] | ||
Post subject: | Need help for my minesweeper game | ||
I am trying to make a minesweeper game but i got stuck and don't know what to do My intention is to check the surrounding tiles for every tile that does not contain any mine and put the number of mines around it in that tile but when i execute it, only 1s appear in the tiles and some tiles don't even have a number in it even though it's beside a mine Can anyone help me? These are the codes so far
|
Author: | DemonWasp [ Wed Mar 18, 2009 6:06 pm ] |
Post subject: | RE:Need help for my minesweeper game |
Think about how you would do this on pencil and paper. Get some graph paper, place some mines on it, and solve the problem manually. Either use that as the inspiration for how to solve the problem algorithmically, or tell us what you came up with, and we'll help you. |
Author: | TheFerret [ Wed Mar 18, 2009 6:14 pm ] |
Post subject: | RE:Need help for my minesweeper game |
Something that will help with this problem is recursion... |
Author: | The_Bean [ Wed Mar 18, 2009 6:36 pm ] | ||||
Post subject: | Re: Need help for my minesweeper game | ||||
He actually has it working somehow in that mess of stuff, he just messed up 2 simple things.
Should be
There is a much shorter and simpler way though. |
Author: | Johnny19931993 [ Wed Mar 18, 2009 7:26 pm ] |
Post subject: | Re: Need help for my minesweeper game |
The_Bean @ Wed Mar 18, 2009 6:36 pm wrote: There is a much shorter and simpler way though. really?! Can you teach me? Cuz this program I made confused myself |
Author: | DemonWasp [ Thu Mar 19, 2009 12:38 am ] |
Post subject: | RE:Need help for my minesweeper game |
You already know the locations of all of the mines (either because you've got them marked in a grid, or because you've got a list of all their locations). For each mine, just add 1 to all of the counters in the 8 neighbouring squares. I'm confused as to how one would use recursion to solve this though - seems like a lot of effort for what amounts to a for-loop or two. |
Author: | Johnny19931993 [ Thu Mar 19, 2009 6:46 pm ] | ||
Post subject: | Re: Need help for my minesweeper game | ||
I took your advice and modified part of the program that calculate the number on the tile into this
Instead of adding the number from the blank tiles, I changed it so it adds the number from the mine tiles But something's still wrong... Some tiles that are suppose to have a number in it apparently don't have a number This is an example : ![]() The 4 that i circle should be a 3 And the other circles are tiles that are suppose to have a number in it |
Author: | DemonWasp [ Fri Mar 20, 2009 1:05 am ] |
Post subject: | RE:Need help for my minesweeper game |
It looks to me like you have a misplaced end-if (based on the intenting). Press F2 to indent properly and check that it looks like you expected. |
Author: | Johnny19931993 [ Fri Mar 20, 2009 2:50 pm ] |
Post subject: | Re: Need help for my minesweeper game |
Some numbers are still wrong though.... ![]() |
Author: | DemonWasp [ Fri Mar 20, 2009 2:55 pm ] |
Post subject: | RE:Need help for my minesweeper game |
Can you post your code as it exists now? I tried assembling your new method with your existing code, but you've made substantial other edits. |
Author: | Johnny19931993 [ Fri Mar 20, 2009 5:09 pm ] | ||
Post subject: | Re: Need help for my minesweeper game | ||
Yes of course
|
Author: | copthesaint [ Sat Mar 21, 2009 8:25 am ] |
Post subject: | RE:Need help for my minesweeper game |
I haven't really tried to slove this problem but I know if you were to redo your program, you may solve the problem. The problem I think is just in your math somewhere. So redoing the program may eliminate the problem. Don't just copy and paste if you do redo it because that won't solve any problems. Also it would be good to redo your program now while you only have 150 lines. |
Author: | copthesaint [ Sat Mar 21, 2009 8:42 am ] | ||
Post subject: | Re: Need help for my minesweeper game | ||
Hmm I think I found your problem... Look at this.
Well this may be your problem. you have 1 to many if conditions. when normally you would have 8 for this. Eg. xxx xMx xxx Count the X's you only want to increase the number at the x's once BTW I have the fixed program but I'm not allowed to give you it (compsci's rules) So you can fix this but look for repition in your code. |
Author: | Johnny19931993 [ Sat Mar 21, 2009 11:04 am ] |
Post subject: | RE:Need help for my minesweeper game |
Thank you very much I fixed the problem now and the program can finally run normally Thanks for your help |
Author: | BigBear [ Sat Mar 21, 2009 11:09 am ] |
Post subject: | RE:Need help for my minesweeper game |
Care to post the finish product? |
Author: | copthesaint [ Sat Mar 21, 2009 12:59 pm ] |
Post subject: | RE:Need help for my minesweeper game |
Big Bear he hasn't acually finished the game yet (you don't loss if you click a mine). It's really easy BigBear to fix what he has done but if you just want the fixed code of this I will be more then happy to pm the code too you if you want. |
Author: | BigBear [ Sat Mar 21, 2009 1:01 pm ] |
Post subject: | RE:Need help for my minesweeper game |
That's what I thought I was wondering if he wanted more suggestions. I also fixed it ![]() |
Author: | copthesaint [ Sat Mar 21, 2009 1:04 pm ] |
Post subject: | RE:Need help for my minesweeper game |
Ohh no he's probably fine because I added 3 lines and made his game over effect. I'm sure he will post the finished version soon since there's not much left to do. |
Author: | Johnny19931993 [ Sun Jul 12, 2009 6:54 pm ] |
Post subject: | Re: RE:Need help for my minesweeper game |
BigBear @ Sat Mar 21, 2009 11:09 am wrote: Care to post the finish product?
http://compsci.ca/v3/viewtopic.php?p=189917 |
Author: | chopperdudes [ Thu Jul 23, 2009 6:28 pm ] |
Post subject: | RE:Need help for my minesweeper game |
hmmm interesting, i wonder how you openned up the empty fields if you didn't use recursion of some sort (ie. DFS) |