コード例 #1
0
        /// <summary>
        /// Funkcja wywoływana przy kazdym odswierzeniu okranu
        /// </summary>
        /// <param name="sender">Obiekt wysylajacy zdazenie</param>
        /// <param name="e">Argumenty zdarzenia</param>
        public void UpdateTime(object sender, UpdateEventArgs e)
        {
            for (int index = 0; index < colonists_.Count;)
            {
                if (colonists_[index].HP.Value > 0f)
                {
                    index++;
                    continue;
                }

                colonists_[index].Die();
                colonists_.Remove(colonists_[index]);
            }

            foreach (Men colonist in Colonist.Where(c => c.Job == null))
            {
                string stateSleep = MakeDecision(colonist.RestF, colonist.Laziness);
                string stateWork  = MakeDecision(colonist.HP, colonist.Laziness);

                if (stateSleep == "Sleep")
                {
                    Bed bed = Constructs.Where(c => c is Bed)
                              .Cast <Bed>()
                              .FirstOrDefault(b => b.State == Construct.Status.Done && b.IsFree);

                    colonist.Job = new SleepJob(colonist, bed);
                }
                else if (stateWork == "Work" && JobQueue.Count > 0)
                {
                    colonist.Job = JobQueue.Dequeue();
                }
                else if (stateWork == "RestF" || colonist.HP != colonist.HP.MaxHP)
                {
                    colonist.Job = colonist.Rest;
                }
            }
        }