Let's imagine game like Heroes of Might and Magic, or Master of Orion, or your turn-based game of choice. What is the game logic behind making next turn? Are there any materials or books to read about the topic? To be specific, let's imagine game loop:

void eventsHandler(); //something that responds to input
void gameLogic(); //something that decides whats going to be output on the screen
void render(); //this function outputs stuff on screen

All those are getting called say 60 times a second. But how turn-based enters here? I might imagine that in gameLogic() there is a function like endTurn() that happens when a player clicks that button, but how do I handle it all? Need insights.


2 Answers 2


A turn based game is going to be governed by a state machine. Basically, you would lay out a series of states that can occur in a logical order.

At a high level, a player's turn could be the start of a new state, followed by all the possible actions that are allowed during that turn.

For instance

  • State - change player
    • it is now player 1's turn
  • Actions allowed
    • attack
      • select enemy to attack
    • defend
      • select unit to defend
    • move unit
      • select unit to move
      • check to ensure movement is allowed
    • etc

Obviously this will balloon quite quickly, as I've only sketched out an extremely limited plan. Having a good grasp on possible states early on will mean that you should be in a good position to implement. I'd highly stress sketching out exactly how you want the game to run....a good turn-based game requires a lot of planning IMO.

  • \$\begingroup\$ A fairly old school project of mine that was a 3month development attempt at Final Fantasy Tactics :) Uses a state machine (a few of em actually) as described above. sourceforge.net/projects/bpfat \$\endgroup\$
    – James
    Commented Feb 8, 2011 at 1:46
  • \$\begingroup\$ Hey, what about Game Engine for turn-based strategy? Could you advice anything? May be Unreal engine could fit? \$\endgroup\$
    – Rantiev
    Commented Jul 11, 2015 at 19:31
  • \$\begingroup\$ To each his own. If you are comfortable with the Unreal engine there is nothing wrong with that. Just depends which mechanics you want to take advantage of. A quick search indicates that a toolkit current exists for the Unreal engine for helping to create turn-based strategy games, though it isn't free. \$\endgroup\$
    – erik
    Commented Jul 12, 2015 at 3:25

I have recently built a turn based strategy game similar to Master of Orion (it's only single player right now, multi-player would be a bit more complex, but a similar idea), here is what my endTurn function logic looks like (in my main Game Controller class):

//for all computer players:

//for all players

//for all players
endTurn(player)//see this function below

//for all planets

//for all players

//check to see if any players were destroyed or if the game is over

My player end turn function will perform functions specific to that player that isn't affected by the order it takes place between players:





Where appropriate, these functions return status messages and/or trigger events so that the GUI can show what happened during the turn or let the player know a computer was destroyed, etc...

  • \$\begingroup\$ could you please provide source code just to check out? Would be great help. Just for educational purposes. \$\endgroup\$
    – Dvole
    Commented Feb 8, 2011 at 18:59
  • \$\begingroup\$ @Dvole I'm currently working on converting the code from Silverlight/C# to JavaScript using the HTML5 canvas tag. Once I finish I plan on open sourcing the code and at that time you are more than welcome to see exactly how I've implemented this function. If it helps to get context you can play my Space Strategy game here: Astriarch - Ruler of the Stars \$\endgroup\$ Commented Feb 8, 2011 at 21:45
  • 2
    \$\begingroup\$ @Dvole It's taken me quite some time, but I just open sourced the Silverlight version of Astriarch. If you are still interested you can download the source code from github here: github.com/mpalmerlee/Astriarch/tree/Silverlight \$\endgroup\$ Commented Nov 14, 2012 at 15:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .