예제 #1
0
        public GameLogic(int dayDuration, int yearDuration, ViewController viewController)
        {
            this.Controller          = viewController;
            this.ConditionController = new ConditionController();
            this.ActivityController  = new ActivityController();
            this.Running             = true;
            this.IsRandomActivity    = false;
            this.Factory             = new CharacterFactory();
            this.CurrentCharacter    = Factory.getNewCharacter();
            this.Time             = new GameTime(dayDuration, yearDuration);
            this.CurrentActivity  = ActivityController.findActivity("walk");
            this.CurrentCondition = null;
            Thread thr = new Thread(new ThreadStart(GameCicle));

            thr.Start();
        }
예제 #2
0
 public void GameCicle()
 {
     NewDay();
     while (Running)
     {
         this.Controller.updateTime(Time.GetCurrentTime().ToString());
         if (Time.IsNewDay())
         {
             this.Controller.updateConsole("--- New day ---");
             this.CurrentActivity = ActivityController.findActivity("walk");
             if (Time.IsNewYear())
             {
                 this.Controller.updateConsole("--- New year ---");
                 NewYear();
             }
             NewDay();
         }
         CheckRandomEvents();
         if (IsRandomActivity)
         {
             if (randomEvent())
             {
                 this.Controller.updateConsole("Time: " + Time.GetCurrentTime().ToString() + " Day: " + Time.GetCurrentDay().ToString() + " Year: " + Time.GetCurrentYear().ToString());
                 this.Controller.updateConsole("Random Event: " + CurrentActivity.Name);
                 this.Controller.updateActivity(CurrentActivity.Name);
                 CurrentCharacter = CurrentActivity.ExecuteStrat(CurrentCharacter);
                 //Console print for fight
                 if (CurrentActivity.Name.Equals("fight"))
                 {
                     this.Controller.updateConsole("Fight log: \n" + ((Fight)CurrentActivity).Log);
                     this.Controller.Enemy = Image.FromFile(((Fight)CurrentActivity).Enemy.Images[0]);
                     this.Controller.moveSprite(((Character)this.CurrentCharacter).Speed);
                     Thread.Sleep(CurrentActivity.Duration);
                 }
                 Time.WaitActivity(CurrentActivity.Duration);
                 Thread.Sleep(CurrentActivity.Duration);
                 this.Controller.Enemy           = null;
                 this.Controller.CurrentActivity = "walk";
             }
         }
         else
         {
             CurrentActivity = ActivityController.findActivity(Controller.GetActivity());
             if (CurrentActivity.Name.Equals("consume"))
             {
                 CurrentCharacter = ((Consume)CurrentActivity).ExecuteStrat(CurrentCharacter, this.Factory.getItem(this.Controller.CurrentItem));
             }
             else
             {
                 CurrentCharacter = CurrentActivity.ExecuteStrat(CurrentCharacter);
             }
             if (CurrentActivity.Name.Equals("walk"))
             {
                 this.Controller.moveSprite(((Character)this.CurrentCharacter).Speed);
                 this.Controller.updateActivity("walk");
             }
             else
             {
                 this.Controller.updateConsole("Time: " + Time.GetCurrentTime().ToString() + " Day: " + Time.GetCurrentDay().ToString() + " Year: " + Time.GetCurrentYear().ToString());
                 Console.WriteLine("Normal Event: " + Controller.GetActivity());
                 this.Controller.updateConsole("Normal Event: " + Controller.GetActivity());
             }
             Time.WaitActivity(CurrentActivity.Duration);
             Thread.Sleep(CurrentActivity.Duration);
             this.Controller.CurrentActivity = "walk";
         }
         Thread.Sleep(1000);
         Time.incrementTime();
         this.Controller.updateCharInfo((Character)this.CurrentCharacter);
         if (this.CurrentCondition == null)
         {
             this.Controller.updateOkAppearance(((Character)this.CurrentCharacter).Level);
         }
     }
 }