Building a Mine Sweeper Game using Dart's Flutter Framework (Part 2)

What Will I Learn?

  • You will how to model the state of a minesweeper application with booleans
  • You will how to break code into binary solutions in a Flutter project
  • You will how to use random numbers to generate random elements for a two dimension list in Dart
  • You will learn how to use Unicode characters and codes in Dart Strings and Flutter Widgets

Requirements

Difficulty

  • Intermediate

Description

In this Flutter video tutorial, we continue making the Minesweeper game. Having built out the basics of our UI and state, we can create more specific UI widgets to model how our tiles should look when they have been** pushed or flagged**. This includes, tiles that have numbers on them, tiles that have nothing on them, tiles with mines in them and tiles that are closed. We also look at how we can model the two dimensional list of our board using Boolean values. In this way we can generate the mines for our application in a random manner.

We split our problem into binary solutions. Tiles with mines versus tiles with out mines and Tiles that are open versus tiles that are closed. For the first binary problem, we create a new two dimensional list with eighty one elements in it. This list contains all false values at its initialization. We then use a random number generator to intersperse true values into the two dimensional list which allows us to model when we have a mine on a tile (when its true) versus when we do not (when its false).

For our second binary problem, we create two new stateless widgets to model our closed and opened tile states. When the tiles are closed, they can have a flag on them or they can have nothing on them. We use two different containers to make the closed tiles look three dimensional. When our tiles are open, they can have a number, a mine or nothing in them. We add a unicode value to represent our flag and mines and we flatten out the open tiles.

The source code for this project can be found here

The freeware minesweeper game that we keep referring too can be found here

Video Tutorial

Related Series Tutorials

Projects and Series

Stand Alone Projects:
Calculator Application
Movie Searcher Application

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
10 Comments