Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

enter image description here

The picture above shows 2 players. Each containing 3 characters. I want to know how to make a Turn based event starting with player 1 alternating turns with player 2. And in every alternation each character gets a turn. If a character dies, the next character on the same team goes, and so on.

How would I create this? Is there a tutorial? I haven't made any turn-based games so I don't know how to program these kinds of stuff.

share|improve this question
1  
possible duplicate of How to implement turn-based game engine? –  michael.bartnett Aug 28 '12 at 20:26
    
It's far from being a duplicate of that. Linked question is about a general problem, answered with code structure of a whole game, while this is a specific problem having specific solutions. –  Markus von Broady Sep 27 '12 at 23:06
    
@MarkusvonBroady I initially disagreed, but saw the specifics reflected in your answer. And based on your answer, this might be a better fit for SO, since it's fundamentally about nested loops. –  michael.bartnett Sep 28 '12 at 1:10
    
Hi @michael.bartnett , this is not a question about nested loops, it would be, if Blue wanted to place a statement in lower level of nested loop, to skip to next step in higher iteration, or had some similar problem. This question is about a gameplay mechanic solution, it could be even denied on SO as too general, without any example code not working. And please notice this: area51.stackexchange.com/faq "When voting, focus on your site Don't worry about whether a question might be asked on another site. Your goal is to make the best possible site for this community." –  Markus von Broady Sep 28 '12 at 8:16
    
@MarkusvonBroady Although Blue is not asking about nested loops and has dressed it up in a turn-based game scenario, that's what the fundmental concept is: Foreach character in foreach player's group of characters. It felt out of place on the site to me because it is so general and only nominally related to gamedev. The other question covered approaches to handling player turns more thoroughly, so that's why I suggested the duplicate. –  michael.bartnett Sep 28 '12 at 15:54
show 1 more comment

3 Answers 3

Assuming you have 2 players always, you'll then need, for each player:

  • A list containing their characters
  • A counter for which of their characters is currently active

As the players trade turns their character counter should go up until it hits it's maximum size (3?) and then start back over at 1. Should a character die, take appropriate action to keep the counter correct. This is something your overall game needs to keep track of, only changing after a turn has been completed.

share|improve this answer
add comment

I don't know Unity, so treat this as a pseudo-code:

var charList:Array = new Array ();

var continueLoop:Boolean = true;
for ( var i:int = 0; continueLoop; i++ ) {
   continueLoop = false;
   for each ( var p:Player in players ) {
      if ( p.units.length > i ) {
         charList.push ( p.units[i] );
         continueLoop = true;
      }
   }
}

Now divide the turn to charList.length number of rounds, and activate the charList[current_round] unit on beginning of every round. Sort player.units by unit speed, if you want to give them initiative in Heroes of Might and Magic III style.

share|improve this answer
add comment

You could simply queue the players in order and just dequeue the first in line. The trigger to add them to the queue totally depends on your system ( I think a state machine could be in order here ). For example; if your character order depend on various triggers like stats and timers. You should monitor their properties and add them to the queue if a certain conditions are met.

I can't really give you any specific code or an example because it's specific to your system obviously. Look up how queues work if you don't know them yet.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.