For loops and Arrays

0 favourites
  • 2 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Hi, I want to randomly spawn mines for a minesweeper game I am making. I think I have to use a 'For' loop, an 'Array', and a 'For Each', but I am not sure. I think I have to pick a random X and Y coordinate, make sure it doesn't already contain a mine, if not put a mine in it; would a 'For Each' be good for this?

    I know that an array originally contains a 0 in each cell, and if I change the value to 1 for example, then I can consider that 1 means there is a mine.

    In order to check if the cell at the coordinates I picked is equal to 0 or 1, should I use a 'For Each' and how do I implement it within the 'For' loop so that if it is 0, I can modify to 1 and go to the next "For" loop iteration. Otherwise, I will want to pick new random coordinates and do that check again right?

    P.S. I am using a TileMap

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • An example without Array and Tilemap but maybe an option for you:

    onedrive.live.com/redir

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)