help with minesweeper game?
Cointoss
Member Posts: 31
I'm trying to create a minesweeper game but I have no idea how to put the bombs in random places, or how to make the numbers match to where the random bombs are. Does anyone have any ideas on how to do this? Thanks!
Comments
A much harder aspect is figuring out how to display the correct number that matches the number of safe squares adjacent. I don't have an answer for you but I can tell you you'd need to be pretty comfortable with tables in GameSalad, so start there and learn all you can from videos related to tables.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Currently I don't have the time to make a demo, or explain in great depths, but to get you on the right path I would recommend is,
A table is needed for the required grid size, each cell represents an actor. You can do this by doing ones and zeros, where zero is a blank spot and a one is a bomb.
For each actor, it should check its cells surrounding it to see if there is a bomb next to it, if so then add one to its self. Bomb count. The more bombs that are around the higher that number is going to be. All that actor has to do then is to display it.
But as said, I don't know how much your experince with tables, because they are going to be the fundamental building blocks for this type of game.
Plus @KevinCross has been making his own twist on it so I am sure if your lucky he will provide some insightful information, if not feel free to PM and I will take you through the steps.
Keep on developing
As @tatiang and @Jeromy have mentioned it does help to have an understanding of tables in GameSalad.
I'll definitely try getting a better understanding of tables so I can make my game! I've never tried using one before
Thanks for the responses everyone! Very helpful
Please note that in this example it doesn't know that it's the end of the game if you find a mine, nor does it have a button or the code to reset the board. This wouldn't be hard to add in.
It's up to you how you generate the grid to play on. In MineScroller I'm using loops but because 10.4.1 hasn't got loops I've had to use some other code to create the grid quickly. There are several different methods for creating loops in 10.4.1. Of course if you don't want the grid to ever change you could place the tiles on the scene manually but that's quite a task.
All this example is really meant to show is how to randomly place mines, and how to show the correct numbers when revealing the tiles.
It doesn't have flags but has a table for it. I did have flags in an early version of MineScroller but removed them because it was pointless flagging tiles that were scrolling off the screen. They're easy enough to add in.
EDIT: replaced the link due to the problems mentioned below where it wouldn't open in 10.4.1
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
Just create a blank project and do nothing with it, just save it with name "MineSweeper"
Then right click on the "MineSweeper" project and select Show Package Contents and you will see all the filés. Delete all of them and replace them with the filés in the folder. Then you should be able to open it
Here's a 10.4.1 version. Sorry
https://www.dropbox.com/s/mxiem9rna6tr8u8/Minesweeper for 10.4.1.zip
EDIT: I've replaced the link in the comment above in case anyone downloads from that comment in the future
For placing them, I would assume you can do something as simple as a "place flag" toggle. When it's inactive, clicking a square on the minefield checks for a mine, when it is active clicking a square spawns a flag actor in that location.
For calculating if they're in the correct place, well that really depends on how you're handling the mines. If you're using a table, then comparing the flag to the relevant table cell should do the trick. If the mines are hidden actors, doing an "if actor overlaps" rule should identify if the flag is correctly placed.
At the end of the day though, the flags are going to be too deeply tied into how you've handled other aspects of the game for anyone to give you any concrete answers without a fair bit more information.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
and I used this that @kevincross made: https://www.dropbox.com/s/mxiem9rna6tr8u8/Minesweeper for 10.4.1.zip and there's a table for the flags but I'm not really sure how to set it up?
Once you have the button and it's been toggled on to place flags it's something like
If square is pressed and revealed = 0 and flagsButtonOn = 1
.. If flags table cell = 0
.... Change image to flagged
.... Update flags table by setting it as 1
.. Otherwise
.... Change image to hidden
.... Update flags table by setting it as 0
On the normal reveal rules you have at the moment you need to add to those rules a check to see if the flags table is 0 before showing the square, as you don't want to show the square if it's flagged.
That's the best I can do in a forum post at 6 am unfortunately in all of the back ups of my game I don't seem to have the flags code in either them.
If you know how to check to see if something is touched and held for longer than 0.4 seconds before released that would be a better way to flag a square.
If I can throw together something in the next couple of days and update my original file I sent above then I will. I've got a little more spare time now.
Toggle:
if Actor receives event touch is pressed
Change attribute game.flagsbuttonon to: 1
Grid:
if actor receives event touch is pressed
if attribute self.revealed=0
if attribute game.flagsbuttonon=1
if attribute self.flagged=0
then:
change image to flagged
change attribute self.flagged to 1
otherwise:
change image to hidden
change attribute self.flagged to 0
and I constrained attribute self.flagged to tableCellValue(game.tblFlagged, self.gridY, self.gridX)
This is the last thing I need to do before I publish my app but I can't figure it out! It seems impossible i've tried everything i can think of