I've gotten an idea on how I want to create minesweeper. (Using a matrix and such.)
But how would I work with checking adjacent spaces and displaying the number on that space.
Any formulas/suggestions.
I just finished (almost) a minesweeper clone for the CSE.
I actually did not use a matrix at all, just lists. If you want me to give you an idea on how I did it, here goes:
# of mines -> M (pretend M is the number of mines)
Randomly place mines; I'll let you figure that out.
Loop through each square and add 1 if there is a mine touching it.
That's pretty much what I did. If you need actual code to help you visualize it, feel free to ask, I can help.
Could I see? I know how to do the random mines...
So once you have you mines, you need to set each square with a number corresponding to how many mines are touching it.
Here is a general outline of how I did this:
-Create a loop to loop through each mine, start at the top leftmost mine to keep track easier.
-Add 1 to everysquare that is touching the mine, make a conditional that won't check squares off the grid. Also add a conditional that checks to make sure the adjacent square isn't another mine before adding 1.
-Tada! That should work. Although I did it a bit different, in a slower way :p
gaventemples31415 wrote:
Could I see? I know how to do the random mines...
His Minesweeper is in the Cemetech Archives, right here:
http://www.cemetech.net/programs/index.php?mode=file&id=948
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement