Beispiel #1
0
 public void SetActiveAnimal(Animal a, TamagotchiContext db)
 {
     this.ActiveAnimal                        = a.AnimalId;
     this.ActiveAnimalNavigation              = a;
     this.ActiveAnimalNavigation.LifeStage    = db.LifeStages.Where(x => x.StageId == this.ActiveAnimalNavigation.LifeStageId).FirstOrDefault();
     this.ActiveAnimalNavigation.AnimalStatus = db.AnimalStatuses.Where(x => x.StatusId == this.ActiveAnimalNavigation.AnimalStatusId).FirstOrDefault();
     db.SaveChanges();
 }
Beispiel #2
0
        public void UpdateStat(Function f, TamagotchiContext db)
        {
            db.Histories.Add(new History()
            {
                Function = f, Age = this.Age, FunctionId = f.FunctionId, AnimalId = this.AnimalId, Animal = this, AnimalStatus = this.AnimalStatus, AnimalWeight = this.AnimalWeight, Happiness = this.Happiness, Hunger = this.Hunger, Hygiene = this.Hygiene, AnimalStatusId = this.AnimalStatusId, LifeStage = this.LifeStage, LifeStageId = this.LifeStageId
            });
            this.Hunger    += f.HungerImpact;
            this.Hygiene   += f.HygieneImpact;
            this.Happiness += f.HappinessImpact;

            if (this.Hunger > 100)
            {
                this.Hunger = 100;
            }
            if (this.Hygiene > 100)
            {
                this.Hygiene = 100;
            }
            if (this.Happiness > 100)
            {
                this.Happiness = 100;
            }

            if (this.Hunger < 0)
            {
                this.Hunger = 0;
            }
            if (this.Hygiene < 0)
            {
                this.Hygiene = 0;
            }
            if (this.Happiness < 0)
            {
                this.Happiness = 0;
            }
        }