help with minesweeper game?

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    There are many tutorials that deal with how to randomize actor positions: https://www.google.com/search?q=random+gamesalad&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

    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

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Let me see what I can strip out from my minesweeper game over the next week or so.
  • Tiny_IdeasTiny_Ideas Member Posts: 326
    Tables my friend, tables.
    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 :D
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I'm going to be busy over the next few days but I will definitely share the basics of my version of Minesweeper: MineScroller, without the scrolling and power ups soon. Maybe this weekend at some point.

    As @tatiang and @Jeromy have mentioned it does help to have an understanding of tables in GameSalad.
  • CointossCointoss Member Posts: 31
    @KevinCross thank you, that will help me a lot!

    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
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited December 2013
    Here's a basic version: https://www.dropbox.com/s/mxiem9rna6tr8u8/Minesweeper for 10.4.1.zip

    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
  • CointossCointoss Member Posts: 31
    @KevinCross Unfortunately I'm having a hard time downloading your example! When I download it it comes up as a file with a lot of parts, so I tried compressing it into a .zip file but gamesalad still won't open it. Do you or anyone else know how I can open it on my Mac? Thanks! (Sorry to bother you, I'm very new to this!)
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    @Coin toss -- it's a Nightly Build project file. You need to be a GameSalad PRO user to open it.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    It's not a nightly build project. I'm like 95% certain I built it in 10.4.1. Is it a Windows/Mac thing?
  • FajlajpFajlajp Member Posts: 666
    I was able to open it without being pro.
    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 :)
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited December 2013
    Grrrr, I know for certain I started out in GameSalad 10.4.1 but somehow I ended up building it in a nightly build >.< Good job I said I was only 95% sure above

    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
  • CointossCointoss Member Posts: 31
    Thank you so much! This will help me a lot, I really appreciate it! :)
  • CointossCointoss Member Posts: 31
    I've finished everything for my game except for one thing- the flags! I've tried a lot of different things but I can't figure it out. Could anyone tell me what I need to do or where to start to get the flags to work?
  • ArmellineArmelline Member, PRO Posts: 5,372
    Do you mean placing the flags, or calculating if they're in the correct place?

    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.
  • CointossCointoss Member Posts: 31
    Yeah I was thinking of doing something like that except changing the image on the one spot of the table that is clicked on to the flag image, but when I try doing it that way the whole table changes to the flag image.

    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?
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    The easiest option for you would be to have a button on the screen that toggles between flags and normal revealing of squares. In my version I checked to see if they held down on any square for longer than 0.4 seconds.

    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.
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    I can you started a thread about checking for extended touches so you've probably got it sorted now :)
  • CointossCointoss Member Posts: 31
    edited December 2013
    @KevinCross Sorry I still don't have it figured out! When I press the toggle and then click on one of the grid squares it only turns red for a second then the image changes to one of the revealed numbers! This is what I have right 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)

  • CointossCointoss Member Posts: 31
    I keep trying different things but nothing is working! I tried a place flag toggle that spawns a flag actor when its true, but it affects the grid underneath and reveals the square instead of reminding them not to reveal the square! and it allows the player to put flags anywhere, not corresponding with the grid

    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
  • CointossCointoss Member Posts: 31
    Never mind I finished!! I'm so excited to publish it thanks for everyones help! :D
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Never mind I finished!! I'm so excited to publish it thanks for everyones help! :D
    Congratulations, looking forward to seeing it when it's released, and sorry for the delays in replying, it's normally really really early in the UK when you tag me in your comments.
Sign In or Register to comment.