Building a Mine Sweeper Game using Dart's Flutter Framework (Part 4, Final)

What Will I Learn?

  • You will learn how to create a fail state and win state for Minesweeper
  • You will learn how to add a timer to a flutter application
  • You will learn how to add widgets to the bottom of the appbar widget
  • You will learn about the preferred sized widget

Requirements

Difficulty

  • Intermediate

Description

In this Flutter video tutorial, we finish the Minesweeper application by adding a true fail state, win state, a timer, and a scoreboard. To add these features we need to create a few new global variables for our main stateful widget. These variables help us determine whether or not the user has lost the game, how many mines the user has detected, and an instantiation of a Stopwatch object and a Timer object. We initialize all of these variables inside of the reset board function so that we can use this function to reset the game when the user hits a fail state or wants to just reset the board state. The timer which acts like a stream, needs to be initialized and disposed of properly so that it will be consistent. We also make sure to have the timer run the set state function for our stateful widget every second so that when the stopwatch updates it will show on the board.

With these new global variables, we are able to apply various different boolean checks to make sure that the user can not do various things and to make sure that the board will change based on the state of the game. This includes the ability to disable the tiles when the user has hit a fail state and show a win or loss message. We also add functionality that will show the position of all of the mines when the user loses the game by having the board update all eighty one of its tiles and then changing the mine tiles to TileState.revealed. We make use of a prefered size widget in our app bar so that we can add the timer text and the win/loss messages into the app bar of our application. We also add a reset button into the app bar.

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

Curriculum

Related Series Tutorials

Projects and Series

Stand Alone Projects:
Building a Calculator
Movie Searcher Application

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
14 Comments