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:

  1. Randomly choose who to start, the user or the computer.

  2. If the choice is the computer:

    1. Play the first move.

    2. Set the current player to the user.

    3. Update the game state.

  3. If the choice is the user:

    1. Update the game state.

Get hands-on with 1400+ tech skills courses.