Solution: Build a Tic-Tac-Toe Game using Flutter BLoC
View the solution of the tic-tac-toe exercise built with Flutter BLoC.
The tic-tac-toe game is a great way to test what you learned about Flutter BLoC in this course. Now, let’s see a possible solution to the challenge.
Implementing GameCubit
The first Cubit we have to implement is the GameCubit
located in lib/cubits/game_cubit/game_cubit.dart
. This is the Cubit that handles all the game states.
The startGame()
function
In the startGame()
function, our goal is to do the following:
Randomly choose who to start, the user or the computer.
If the choice is the computer:
Play the first move.
Set the current player to the user.
Update the game state.
If the choice is the user:
Update the game state.
Get hands-on with 1400+ tech skills courses.