バトルシーケンスは、ゲーム内のミニゲームとして想像します。更新ティック(またはターンティック)は、これらのイベントを処理するコンポーネントに向けられます。このアプローチは、バトルシーケンスロジックを別のクラスにカプセル化し、メインのゲームループをゲーム状態間で自由に移行できるようにします。
void gameLoop() {
    while(gameRunning) {
        if (state == EXPLORATION) {
            // Perform actions for when player is simply walking around
            // ...
        }
        else if (state == IN_BATTLE) {
            // Perform actions for when player is in battle
            currentBattle.HandleTurn()
        }
        else if (state == IN_DIALOGUE) {
            // Perform actions for when player is talking with npcs
            // ...
        }
    }
}
バトルシーケンスクラスは次のようになります。
class BattleSequence {
    public:
        BattleSequence(Entity player, Entity enemy);
        void HandleTurn();
        bool battleFinished();
    private:
        Entity currentlyAttacking;
        Entity currentlyReceiving;
        bool finished;
}
TrollとWarriorはどちらも、Entityと呼ばれる共通のスーパークラスから継承します。HandleTurn内では、攻撃エンティティは移動できます。これは、AIの思考ルーチンに相当します。
void HandleTurn() {
    // Perform turn actions
    currentlyAttacking.fight(currentlyReceiving);
    // Switch sides
    Entity temp = currentlyAttacking;
    currentlyAttacking = currentlyReceiving;
    currentlyReceiving = temp;
    // Battle end condition
    if (currentlyReceiving.isDead() || currentlyAttacking.hasFled()) {
        finished = true;
    }
}
fightメソッドは、エンティティが何をしようとしているかを決定します。これは、ポーションを飲む、逃げるなど、相手のエンティティを関与させる必要がないことに注意してください。
更新:複数のモンスターとプレイヤーパーティーをサポートするには、グループクラスを導入します。
class Group {
    public:
        void fight(Group opponents) {
            // Loop through all group members so everyone gets
            // a shot at the opponents
            for (int i = 0; i < memberCount; i++) {
                Entity attacker = members[i];
                attacker.fight(opponents);
            }
        }
        Entity get(int targetID) {
            // TODO: Bounds checking
            return members[targetID];
        }
        bool isDead() {
            bool dead = true;
            for (int i = 0; i < memberCount; i++) {
                dead = dead && members[i].isDead();
            }
            return dead;
        }
        bool hasFled() {
            bool fled = true;
            for (int i = 0; i < memberCount; i++) {
                fled = fled && members[i].hasFled();
            }
            return fled;
        }
    private:
        Entity[] members;
        int memberCount;
}
Groupクラスは、BattleSequenceクラスのEntityのすべての出現を置き換えます。選択と攻撃はEntityクラス自体によって処理されるため、AIは最適なアクションコースを選択するときにグループ全体を考慮することができます。
class Entity {
    public:
        void fight(Group opponents) {
            // Algorithm for selecting an entity from the group
            // ...
            int targetID = 0; // Or just pick the first one
            Entity target = opponents.get(targetID);
            // Fighting algorithm
            target.applyDamage(10);
        }
}