Ejemplo n.º 1
0
        public IActionResult EnemiesTurn()
        {
            int     PlayerId = (int)HttpContext.Session.GetInt32("PlayerId");
            Player  Player1  = _context.player.SingleOrDefault(p => p.PlayerId == PlayerId);
            int?    enconId  = HttpContext.Session.GetInt32("EncounterId");
            Enemies monster  = _context.enemies.Where(m => m.EncountersId == enconId && m.life == true).First();

            Story newStory = new Story();

            if (monster.name == "Spider")
            {
                Spider spider    = _context.spider.Where(m => m.EncountersId == enconId && m.life == true).First();
                int    spideratt = spider.RandomSpiderAttack(Player1);
                newStory.storyBook  = "You were attacked by " + monster.name + " for " + spideratt + " damage";
                newStory.created_at = DateTime.Now;
                newStory.PlayerId   = PlayerId;
                newStory.flag       = 3;
            }
            else if (monster.name == "Zombie")
            {
                Zombie zombie     = _context.zombie.Where(m => m.EncountersId == enconId && m.life == true).First();
                int    zombireatt = zombie.RandomZombieAttack(Player1);
                newStory.storyBook  = "You were attacked by " + monster.name + " for " + zombireatt + " damage";
                newStory.created_at = DateTime.Now;
                newStory.PlayerId   = PlayerId;
                newStory.flag       = 3;
            }
            else if (monster.name == "Orc")
            {
                Orc orc    = _context.orc.Where(m => m.EncountersId == enconId && m.life == true).First();
                int orcatt = orc.RandomOrcAttack(Player1);
                newStory.storyBook  = "You were attacked by " + monster.name + " for " + orcatt + " damage";
                newStory.created_at = DateTime.Now;
                newStory.PlayerId   = PlayerId;
                newStory.flag       = 3;
            }
            else if (monster.name == "Dragon")
            {
                Dragon dragon    = _context.dragon.Where(m => m.EncountersId == enconId && m.life == true).First();
                int    dragonatt = dragon.RandomDragonAttack(Player1);
                newStory.storyBook  = "You were attacked by " + monster.name + " for " + dragonatt + " damage";
                newStory.created_at = DateTime.Now;
                newStory.PlayerId   = PlayerId;
                newStory.flag       = 3;
            }

            if (Player1.health <= 0)
            {
                Player1.health = 0;
                Player1.life   = false;
                _context.Add(newStory);
                _context.SaveChanges();
                return(RedirectToAction("GameOver"));
            }

            SetTemp(0);
            _context.Add(newStory);
            _context.SaveChanges();
            return(RedirectToAction("Moves"));
        }