Turn-based Games

For my group’s project, we have to allow our players to take turns because our project is a multiplayer board game. I had no clue how to implement turns in Unity so I searched for google advice and YouTube tutorials. Immediately, I found many, many tutorials on Pokémon-style turn-based games. Given how popular Pokémon is, this isn’t a big surprise. I have been playing Pokémon ever since I was eight-years-old so I had to resist the urge to take a break from working on my project to start a mini Pokémon-clone Unity project.

After searching for a while I managed to find some tutorials that would be helpful for my project. One is a Pokémon clone that goes into detail on displaying the player prefab, displaying information on what is going on, and on game flow (1) . Another tutorial uses a board game as an example to show how to use changed game states to make a turn-based game (2).

In both tutorials, they use a global enum to control the game state. Let’s call this enum, GameState. We can put various games states into this enum (for example, START, PLAYER_TURN, ENEMY_TURN) and check which of the game states GameState is currently set to. We can also change which state it is in. This way, we can have different actions occur depending on which game state we are in.

In my game, the players go back and forth rolling the dice and whoever reaches the finish tile wins. Right now, I am assuming there are only two players. This means that the game states I need are START, PLAYER_1_TURN, PLAYER_2_TURN, PLAYER_1_WIN, PLAYER_2_WIN. At first I thought I needed a lose state but then I realized that when one player wins, the other player loses so that was unnecessary. By having different game states, I can create a heading at the top of the screen to the let the player know whose turn it is. For example, when the game state is PLAYER_1_TURN, the heading can say something like “Player 1 Turn” or “Player 1 Rolls the Dice.”

I have been stuck trying to figure out turns for a while so I’m pretty happy to have learned about putting game state into a global enum. Now, I can finally get a good chunk of this project working!

Sources:

  1. https://www.youtube.com/watch?v=_1pz_ohupPs
  2. https://www.youtube.com/watch?v=b9-LKprJht0
Print Friendly, PDF & Email

Leave a Reply