Turn Based Event Algorithm

Posted by GamersIncoming on Game Development See other posts from Game Development or by GamersIncoming
Published on 2012-07-10T16:20:17Z Indexed on 2012/07/10 21:25 UTC
Read the original article Hit count: 240

Filed under:
|
|

I'm currently working on a small roguelike in XNA, which sees the player in a randomly generated series of dungeons fending off creeps, as you might expect. As with most roguelikes, the player makes a move, and then each of the creeps currently active on screen will make a move in turns, until all creeps have updated, and it return's to the player's go. On paper, the simple algorithm is straightforward:

Player takes turn
Turn Number increments
For each active creep, update Position
Once all active creeps have updated, allow player to take next turn

However, when it comes to actually writing this in more detail, the concept becomes a bit more tricky for me. So my question comes as this: what is the best way to handle events taking turns to trigger, where the completion of each last event triggers the next, when dealing with a large number of creeps (probably stored as an array of an enemy object), and is there an easier way to create some kind of engine that just takes all objects that need updating and chains them together so their updates follow suit?

I'm not asking for code, just algorithms and theory in the direction of objects triggering updates one after the other, in a turn based manner.

Thanks in advance.

Edited: Here's the code I currently have that is horrible :/

        if (player.getTurnOver() && updateWait == 0)
            {
                if (creep[creepToUpdate].getActive())
                {
                    creep[creepToUpdate].moveObject(player, map1);
                    updateWait = 10;
                }
                if (creepToUpdate < creep.Length -1)
                {
                    creepToUpdate++;
                }
                else
                {
                    creepToUpdate = 0;
                    player.setTurnOver(false);
                }
            }
            if (updateWait > 0)
            {
                updateWait--;
            }

© Game Development or respective owner

Related posts about XNA

Related posts about c#