Creating MineField In Unity (Part 1)

As a mini side-project, I recently made a MineSweeper-style game. Here’s how I did it.

Today’s Objective: Create a class to hold and handle the data of an individual “cell” in the grid, instanced to be used on every cell in the grid.

The Plan:

The original idea was to make a quick and basic game where you chose cells in a grid where each cell had a chance of being either good or bad. The aim of the game was to clear all good cells and/or get the highest score you could before hitting a bad cell.

Score was calculated for each good cell based on how many of its neighbors were bad, thus being a high risk/high reward mechanic.

The Code:

First I create a “Cell” class to hold data about each cell on the grid.

The “Cell” class also needs some functions to facilitate showing/hiding the cell’s information, and checking it’s neighbors for bad cells:

Next is the “GameManager” class, which manages all the game data, from loading PlayerPrefs to displaying the grid cells to managing UI. I could have made this into multiple classes for each area, but it isn’t too big or complicated so one class is fine I think.

But it is a bit of a large class, so I will cover that in full in my next post tomorrow.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store