#include "GameState.h"

void GameState :: gamestateBattleCheckForResultAfterDraw ()
{
  inputBufferIterator = inputBuffer.begin ();
  while (inputBufferIterator < inputBuffer.end ())
    {
      if (inputBufferIterator -> getInput () == INPUT_QUITGAME)
        {
          addQuitCommand ();
        }
      inputBufferIterator ++;
    }

  if (SDL_GetTicks () >= 500 + startTime)
    {
      //check for winners or losers
      if (rulez.determineWinner () == BATTLE_RESULT_PLAYER_WON)
        setNewGameState (GAMESTATE_BATTLE_SHOW_REWARDS);

      if (rulez.determineWinner () == BATTLE_RESULT_PLAYER_LOST)
        setNewGameState (GAMESTATE_BATTLE_GAME_OVER);

      //go to whoever's turn is next.
      if (rulez.determineWinner () == BATTLE_RESULT_NOT_FINISHED)
        {
          rulez.nextTurn ();
          if (rulez.isItPlayerTurn ())
            setNewGameState (GAMESTATE_BATTLE_PLAYER_PHASE);
          else
            setNewGameState (GAMESTATE_BATTLE_ENEMY_PHASE);
        }
    }
}
