Introducing: Minigame Monday! (3D Minesweeper)

Minigame Monday:
    To make sure I keep producing code, games and therefore blog posts, I'm aiming to create a small game every week on Monday (although it might not make it on to the blog the same day). These games will obviously be pretty simple; so far I'm thinking of making some twists on classic games, but that will probably vary. With regards to engine/language, I imagine many of them will be made using Python and pygame (https://www.pygame.org/) due to its simplicity; it makes it quick to get something running on the screen. I'll release the game on itch.io and the code on github (see the links on the sidebar) with each blog post, so you're welcome to try the games yourself and look at how they were put together. Don't expect amazing graphics or intricate detail, but each game should be perfectly playable and hopefully pretty fun!


This week: 3D Minesweeper
  • The concept:
    The idea is pretty simple: In a normal game of minesweeper, the number in each cell tells you the number of mines around it on the sides, up and down, and the diagonals. Here, a third axis would be added to the game, so there are different layers of mines above and below it, making a three dimensional grid. So if you looked at a cell, it would show you the number of mines in the current layer as normal, plus the nine mines in the layer below and the nine mines in the layer above. 
    I must admit, I think the original idea of minesweeper is perhaps a naval setting, as the mines look a bit like sea mines. Obviously in that case you couldn't have layers of mines below and above, but I've always imagined minesweeper takes place underground. When I was a kid, I think I misunderstood the title, thinking that it was a mine being swept of explosives. Either way, I suppose this variant does take place underground, with the miners moving between layers as they try to secure the mine.

  • The challenge:
    The first thing I needed to do was refamiliarise myself with the pygame libraries, and make sure I could get the gameplay essentials running: a main loop, handling user input and redrawing the screen. I decided to make a settings screen first, to give me a chance to practice with pygame and to allow the player some configurability to the game. I put together a decently configurable system involving a list of clickable arrows that could then be added to later. This came in handy as I realised when I started on the main screen that I wanted to allow the user to set the number of mines, in addition to the size of the playing field, but it was easy to add another set of arrows under the framework I'd written.

The settings screen
The settings screen
 
   Getting into the main game, the biggest challenge, as you might expect, is control of the three-dimensional arrays needed to store the game state. To handle this, I had two different arrays: gridObjects, which stored the state of each cell (not seen, seen, flagged or exploded) and gridMines, where each element contained the number of mines around that cell, with the value of -1 if the cell itself was a mine. Using these two arrays, I wrote functions to lay the mines randomly in the grid (side note, I made sure this only happened after the first cell was clicked, then they could be laid in such a manner that the clicked cell couldn't be a mine), calculate the number of adjacent mines to fill in the gridMines array, and open cells (automatically opening around cells with 0 mines around them, and doing so recursively). 

  • The result:
3D Minesweeper gameplay
3D Minesweeper gameplay

    The result is a fun, but very tricky variant on minesweeper. I took a bit of extra time to add a few quality of life features seeing as this is the first minigame, such as right clicking a cell to open cells around it if it is fully flagged, and these came in quite handy when trying to beat it. Normal methods of working out which cells are safe proved ineffective or different, and I found the best strategy was to try to isolate layers to where you knew mines weren't above or below, and then solve them as normal.
    I'm quite happy with how the game turned out, and there aren't too many features I'd like to add that I didn't have time for (other than better graphics of course, but expect that to be a recurring theme throughout the minigame Mondays!). One feature I might add, although it would take a bit of time to implement, would be changing the orientation of the field on command by rotating it, to allow you to have a different look at the mines (for example rotate a 3x4x5 grid to a 4x5x3 grid, and see if that makes it easier to spot mines). The game is downloadable at https://reddragonmakesgames.itch.io/3d-minesweeper, see what you think!

Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Minigame Monday: Covert Behaviour