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.

--

--

--

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Introducing easyApi: Call & test REST APIs in seconds

Floats: Something You Should Know How to Do Even Though There are Better Ways to Achieve the Same…

Modern Distributed Application Deployment with Kubernetes and MongoDB Atlas

Detekt Dangers and custom reports

Identifying Security Pitfalls and Smart Contract Best Practices

CS 373 Fall 2020: Jonathan Randall

Solr upgrade from version 6.X -> 8.X + a Road from Master-Slave to Solr Cloud … Fuss-free!

Automation Testing Guide Website

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
Vincent Taylor

Vincent Taylor

Unity game developer / C# Programmer / Gamer. Australian (Tasmanian) indie games developer for 10+ years. Currently looking for games industry employment.

More from Medium

Creating A Respawn/Checkpoint System In Unity

How to Build and Test your Unity Game

Using the Unity Profiler

Adding a burst laser powerup