package uk.co.patrickhaston.mars;

public class MarsController extends Thread 
{
  private MarsFrame theFrame;
  private MarsModel theModel;
  
  public MarsController(MarsFrame frame, MarsModel model)
  {
    theFrame= frame;
    theModel = model;
  }

  public void run()
  {
    try
    {
      while (true)
      {
        if(theModel.gameStatus == 2)
        {
          if ( (theFrame.currentView == theFrame.MAP_VIEW) || (theFrame.currentView == theFrame.SETTLEMENT_VIEW) )
          {
            switch (theModel.gameSpeed)
            {
              case 0: break;
              case 1: 
                Thread.sleep(2000); 
                nextDay();
                break;
              case 2: 
                Thread.sleep(1000); 
                nextDay();
                break;
              case 3: 
                Thread.sleep(500);  
                nextDay();
                break;
            }
          }
          else
          {
            Thread.sleep(500);  
            theModel.logEvent("marsController update Conversation");
            theFrame.updateConversation();
          }
        }
      }
    }
    catch (InterruptedException e)
    {
    }
  }
  
  public void nextDay()
  {
    // Do all the work of incrementing the model to the next day
    theModel.nextDay();
    theFrame.repaint();
  }
}
