function Hexxgame::startGame(%this)
{
   // start game
   %this.running = true;   
   
   // start harvesting
   resControl.harvest(playerOne);
   resControl.harvest(playerTwo);
   
   // start opponent ai
   opponentAI.analyzeSituation();
   opponentAI.performAction();
}

function Hexxgame::update(%this)
{
   // check for a winner
   if(playerOne.getBases() <= 0)
      %this.endGame(playerTwo);
   else if(playerTwo.getBases() <= 0)
      %this.endGame(playerOne);
}

function Hexxgame::endGame(%this, %winner)
{
   // end game, if it was running
   if(%this.running)
   {
      // reset mouse cursor
      Canvas.setCursor(DefaultCursor);
      
      // play sound
      alxPlay(startEndSound);
      
      // unregister parallax objects
      parallaxReg.unregisterAllObjects();
      
      // show summary
      undisplayHud();
      sceneWindow2D.loadLevel("game/data/levels/common/empty.t2d");
      menuWindow.loadLevel("game/data/levels/common/summary.t2d");
      Canvas.pushDialog(menuWindow);
      
      // show won or lost title
      if(%winner.getId() == %this.humanPlayer.getId())
      {
         menu_wontitle.setVisible(true);
         menu_losttitle.setVisible(false);
      }
      else
      {
         menu_wontitle.setVisible(false);
         menu_losttitle.setVisible(true);
      }
      
      // cleanup
      if(isObject(opponentAI))
         opponentAI.safeDelete();    
      
      if(isObject(playerOne))
         playerOne.safeDelete();

      if(isObject(playerTwo))
         playerTwo.safeDelete();
         
      if(isObject(resControl))
         resControl.safeDelete();
      
      // self destruct
      %this.delete();
   }
}

function Hexxgame::isRunning(%this)
{
   return %this.running;
}

function Hexxgame::setHumanPlayer(%this, %player)
{
   %this.humanPlayer = %player;
}

function Hexxgame::getHumanPlayer(%this)
{
   return %this.humanPlayer;
}

function Hexxgame::setAIPlayer(%this, %player)
{
   %this.AIPlayer = %player;
}

function Hexxgame::getAIPlayer(%this)
{
   return %this.AIPlayer;
}