Esempio n. 1
0
 public void FillPrey(AnimalModel killer, AnimalModel victim, AnimalType typeOfKiller)
 {
     _prey.KillerId     = killer.Id;
     _prey.VictimId     = victim.Id;
     _prey.TypeOfKiller = (int)typeOfKiller;
     _dataBase.InsertID(_prey);
 }
Esempio n. 2
0
 public void WhoKilledWho(AnimalModel sacrifice, AnimalModel killer)
 {
     Console.WriteLine("отработка WhoKilledWho");
     sacrifice.IsDead = true;
     killer.Killer    = sacrifice.Name;
     _dataBase.Update(sacrifice);
     _dataBase.Update(killer);
 }
Esempio n. 3
0
        public void AssignAnimal(string animalName, AnimalModel animal)
        {
            var countSheep  = _dataBase.countAnimal <SheepModel>();
            var countWolf   = _dataBase.countAnimal <WolfModel>();
            var countDuck   = _dataBase.countAnimal <DuckModel>();
            var countHunter = _dataBase.countAnimal <HunterModel>();

            int[] nums     = { countSheep, countWolf, countDuck, countHunter };
            int   allCount = nums.Max() + 1;

            animal.Order += allCount;
            animal.Name   = animalName;
        }
Esempio n. 4
0
        public void AnimalKiller(AnimalModel animal)
        {
            Console.WriteLine("отработка AnimalKiller");
            switch (animal)
            {
            case WolfModel:
                WolfIsKiller(animal);
                return;

            case HunterModel:
                HunterIsKiller(animal);
                return;
            }
        }
Esempio n. 5
0
 public string TextKill(AnimalModel animal)
 {
     if (animal.Killer != null)
     {
         if (animal is WolfModel)
         {
             return($"This {AnimalType.WOLF} tear to pieces {animal.Killer}");
         }
         if (animal is HunterModel)
         {
             return($"This {AnimalType.HUNTER} just kill a {animal.Killer}");
         }
     }
     return(TypeOfAnimal(animal).ToString());
 }
Esempio n. 6
0
        public void WolfKiller_WolfKillHunter(AnimalModel animal, AnimalModel item)
        {
            double hunterLiveCount = _dataBase.animalLiveCount <HunterModel>();

            if (hunterLiveCount <= 1)
            {
                StopTimer();
            }
            WhoKilledWho(item, animal);
            DuckFlyAway();
            string message = $"Волк {animal.Name} разодрал охотника {item.Name}";

            NotifyKillInvoke(message, KillerAnnotation.WOLF_EAT_HUNTER);
            FillPrey(animal, item, AnimalType.WOLF);
        }
Esempio n. 7
0
        public void HunterIsKiller(AnimalModel animal)
        {
            var allCount   = _dataBase.AnimalModelCount <AnimalModel>();
            var allAnimals = _dataBase.GetAnimalModels();

            for (var i = allCount - 1; i >= 0; --i)
            {
                var item = allAnimals[i];
                //охотник валит волка
                if (item is WolfModel && !item.IsDead)
                {
                    HunterKiller_HunterKillWolf(animal, item);
                    break;
                }
            }
            DataChangedInvoke(allAnimals);
        }
Esempio n. 8
0
        public void StartTimer(AnimalModel animal)
        {
            double wolfLiveCount = _dataBase.animalLiveCount <WolfModel>();

            if (_aTimer.Enabled == false)
            {
                _aTimer.Interval = 5000;
                _aTimer.Elapsed += (o, args) => { AnimalKiller(animal); };
                _aTimer.Start();
                _aTimer.AutoReset = true;
                _aTimer.Enabled   = true;
                if (wolfLiveCount == 0)
                {
                    StopTimer();
                }
            }
        }
Esempio n. 9
0
        public AnimalState GetAnimalState(AnimalModel animal)
        {
            if (animal.IsDead)
            {
                return(AnimalState.DEAD);
            }

            if (!animal.IsDead && animal.Killer == null)
            {
                return(AnimalState.ALIVE);
            }

            if (animal.Killer != null)
            {
                return(AnimalState.KILLER);
            }
            throw new Exception();
        }
Esempio n. 10
0
        public string GetKillerID <T>(AnimalModel animal) where T : Prey, new()
        {
            var connection  = new SQLiteConnection(dbPath);
            var victimModel = connection.Table <T>().FirstOrDefault(a => a.VictimId == animal.Id);
            var killID      = victimModel.KillerId;
            var typeKiller  = victimModel.TypeOfKiller;

            switch (typeKiller)
            {
            case (int)AnimalType.HUNTER:
                return(connection.Table <HunterModel>().FirstOrDefault(a => a.Id == killID).Name);

            case (int)AnimalType.WOLF:
                return(connection.Table <WolfModel>().FirstOrDefault(a => a.Id == killID).Name);
            }

            return(null);
        }
Esempio n. 11
0
        public void HunterKiller_WolfKillHunter(AnimalModel animal, AnimalModel item)
        {
            double hunterLiveCount = _dataBase.animalLiveCount <HunterModel>();
            double wolfLiveCount   = _dataBase.animalLiveCount <WolfModel>();

            if (wolfLiveCount / 2 > hunterLiveCount && hunterLiveCount != 0)
            {
                animal.IsDead = true;
                item.Killer   = animal.Name;
                DuckFlyAway();
                FillPrey(item, animal, AnimalType.WOLF);
                _dataBase.Update(animal);
                _dataBase.Update(item);
                string message = $"Волк {item.Name} разодрал охотника {animal.Name}";
                NotifyKillInvoke(message, KillerAnnotation.WOLF_EAT_HUNTER);
                StopTimer();
            }
        }
Esempio n. 12
0
        public void HunterKiller_HunterKillWolf(AnimalModel animal, AnimalModel item)
        {
            double hunterLiveCount = _dataBase.animalLiveCount <HunterModel>();

            if (hunterLiveCount <= 1)
            {
                StopTimer();
            }
            WhoKilledWho(item, animal);
            DuckFlyAway();
            string message = $"Охотник {animal.Name} завалил волка {item.Name}";

            NotifyKillInvoke(message, KillerAnnotation.HUNTER_KILL_WOLF);
            _dataBase.Update(animal);
            FillPrey(animal, item, AnimalType.HUNTER);
            //волк валит охотника
            HunterKiller_WolfKillHunter(animal, item);
        }
Esempio n. 13
0
        public void WolfKiller_HunterKillWolf(AnimalModel animal, AnimalModel hunt)
        {
            DuckFlyAway();
            Timer _timer = new Timer(5000);

            _aTimer.Start();
            _timer.Elapsed  += (o, args) => { WhoKilledWho(animal, hunt); };
            _timer.AutoReset = true;
            _timer.Enabled   = true;
            Console.WriteLine("завалили съевшего овцу");
            FillPrey(hunt, animal, AnimalType.HUNTER);
            string message = $"Охотник {hunt.Name} завалил волка {animal.Name}";

            NotifyKillInvoke(message, KillerAnnotation.HUNTER_KILL_WOLF);
            _dataBase.Update(animal);
            _dataBase.Update(hunt);
            _timer.Stop();
            _timer.Dispose();
        }
Esempio n. 14
0
 public string NameofKiller(AnimalModel animal)
 {
     if (animal.IsDead)
     {
         var killName = _dataBase.GetKillerID <Prey>(animal);
         if (animal is SheepModel)
         {
             return($"This {AnimalType.SHEEP} eliminated by {killName}");
         }
         if (animal is WolfModel)
         {
             return($"This {AnimalType.WOLF} is killed by a hunter {killName}");
         }
         if (animal is HunterModel)
         {
             return($"This {AnimalType.HUNTER} is tear to pieces by a wolf {killName}");
         }
     }
     return("");
 }
Esempio n. 15
0
        public void WolfKiller_WolfKillSheep(AnimalModel animal, AnimalModel item)
        {
            var allCount   = _dataBase.AnimalModelCount <AnimalModel>();
            var allAnimals = _dataBase.GetAnimalModels();

            WhoKilledWho(item, animal);
            FillPrey(animal, item, AnimalType.WOLF);
            string message = $"Волк {animal.Name} сожрал овцу {item.Name}";

            NotifyKillInvoke(message, KillerAnnotation.WOLF_EAT_SHEEP);
            for (int k = allCount - 1; k >= 0; --k)
            {
                var hunt = allAnimals[k];
                if (hunt is HunterModel && !hunt.IsDead)
                {
                    WolfKiller_HunterKillWolf(animal, hunt);
                    break;
                }
            }
        }
Esempio n. 16
0
        public AnimalType TypeOfAnimal(AnimalModel animal)
        {
            AnimalType type;

            if (animal is SheepModel)
            {
                type = AnimalType.SHEEP;
            }
            else if (animal is WolfModel)
            {
                type = AnimalType.WOLF;
            }
            else if (animal is DuckModel)
            {
                type = AnimalType.DUCK;
            }
            else
            {
                type = AnimalType.HUNTER;
            }
            return(type);
        }
Esempio n. 17
0
        public void WolfIsKiller(AnimalModel animal)
        {
            var allCount   = _dataBase.AnimalModelCount <AnimalModel>();
            var allAnimals = _dataBase.GetAnimalModels();

            for (var i = allCount - 1; i >= 0; --i)
            {
                var item = allAnimals[i];
                //волки жрут овцу
                if (item is SheepModel && !item.IsDead)
                {
                    WolfKiller_WolfKillSheep(animal, item);
                    break;
                }
                //волки жрут охотника
                else if (item is HunterModel && !item.IsDead)
                {
                    WolfKiller_WolfKillHunter(animal, item);
                    break;
                }
            }
            DataChangedInvoke(allAnimals);
        }
Esempio n. 18
0
        public void Insert(AnimalModel animal)
        {
            var connection = new SQLiteConnection(dbPath);

            connection.Insert(animal);
        }
Esempio n. 19
0
 public void ActionWithCreatures(string animalName, AnimalModel animal)
 {
     AssignAnimal(animalName, animal);
     AnimalKiller(animal);
     _dataBase.Insert(animal);
 }
Esempio n. 20
0
        public void Update(AnimalModel animal)
        {
            var connection = new SQLiteConnection(dbPath);

            connection.Update(animal);
        }