예제 #1
0
        public IActionResult PlayersTurn(int attk)
        {
            int        PlayerId  = (int)HttpContext.Session.GetInt32("PlayerId");
            Player     Player1   = _context.player.SingleOrDefault(p => p.PlayerId == PlayerId);
            int?       enconId   = HttpContext.Session.GetInt32("EncounterId");
            Encounters encounter = _context.encounters.SingleOrDefault(e => e.EncountersId == enconId);
            Enemies    monster   = _context.enemies.Where(m => m.EncountersId == enconId && m.life == true).First();
            Story      newStory  = new Story();
            Story      newStory2 = new Story();

            if (Player1.Class == "mage")
            {
                Mage Player = _context.mage.SingleOrDefault(p => p.PlayerId == PlayerId);
                if (attk == 1)
                {
                    int attackVal = Player.Attack(monster);
                    attackVal.ToString();
                    newStory.storyBook = "You attacked a " + monster.name + " and did " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 2)
                {
                    Player.Heal();
                    newStory.storyBook = "You used heal";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 4;
                }
                else if (attk == 3)
                {
                    int attackVal = Player.Fireball(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 4)
                {
                    int attackVal = Player.FrostBolt(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
            }
            if (Player1.Class == "hunter")
            {
                Hunter Player = _context.hunter.SingleOrDefault(p => p.PlayerId == PlayerId);
                if (attk == 1)
                {
                    int attackVal = Player.Attack(monster);
                    attackVal.ToString();
                    newStory.storyBook = "You attacked a " + monster.name + " and did " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 2)
                {
                    Player.Mend();
                    newStory.storyBook = "You were mended fight on Hunter.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 4;
                }
                else if (attk == 3)
                {
                    int attackVal = Player.Snipe(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 4)
                {
                    int attackVal = Player.Silencing_Shot(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
            }
            if (Player1.Class == "samurai")
            {
                Samurai Player = _context.samurai.SingleOrDefault(p => p.PlayerId == PlayerId);
                if (attk == 1)
                {
                    int attackVal = Player.Attack(monster);
                    attackVal.ToString();
                    newStory.storyBook = "You attacked a " + monster.name + " and did " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 2)
                {
                    Player.Meditate();
                    newStory.storyBook = "You used meditate.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 4;
                }
                else if (attk == 3)
                {
                    int attackVal = Player.Smash(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 4)
                {
                    int attackVal = Player.Death_Blow(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
            }
            if (Player1.Class == "ninja")
            {
                Ninja Player = _context.ninja.SingleOrDefault(p => p.PlayerId == PlayerId);
                if (attk == 1)
                {
                    int attackVal = Player.Attack(monster);
                    attackVal.ToString();
                    newStory.storyBook = "You attacked a " + monster.name + " and did " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 2)
                {
                    Player.Hide();
                    newStory.storyBook = "You hide from the enemies.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 4;
                }
                else if (attk == 3)
                {
                    int attackVal = Player.Backstab(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 4)
                {
                    int attackVal = Player.Rend(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
            }
            if (Player1.Class == "priest")
            {
                Priest Player = _context.priest.SingleOrDefault(p => p.PlayerId == PlayerId);
                if (attk == 1)
                {
                    int attackVal = Player.Attack(monster);
                    attackVal.ToString();
                    newStory.storyBook = "You attacked a " + monster.name + " and did " + attackVal + " damage.";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 2)
                {
                    Player.Holy_Heal();
                    newStory.storyBook = "You healed yourself";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 4;
                }
                else if (attk == 3)
                {
                    int attackVal = Player.Holy_Light(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
                else if (attk == 4)
                {
                    int attackVal = Player.Smight(monster);
                    newStory.storyBook = "You attacked a " + monster.name + " for " + attackVal + " damage";
                    SetTemp(0);
                    newStory.created_at = DateTime.Now;
                    newStory.PlayerId   = PlayerId;
                    newStory.flag       = 2;
                }
            }
            _context.Add(newStory);
            _context.SaveChanges();
            if (monster.health <= 0)
            {
                monster.health      = 0;
                monster.life        = false;
                newStory2.storyBook = "You killed a " + monster.name;
                SetTemp(-10);
                newStory2.created_at = DateTime.Now;
                newStory2.PlayerId   = PlayerId;
                newStory2.flag       = 2;
                _context.Add(newStory2);
                _context.SaveChanges();
            }
            List <Enemies> enemyCount = _context.enemies.Where(m => m.EncountersId == enconId && m.life == true).ToList();

            if (enemyCount.Count() > 0)
            {
                return(RedirectToAction("EnemiesTurn"));
            }
            int level = (int)HttpContext.Session.GetInt32("Level");

            level++;
            HttpContext.Session.SetInt32("Level", level);
            return(RedirectToAction("firstEncounter"));
        }
예제 #2
0
        static void Main(string[] args)
        {
            RayGun     green    = new RayGun("green ray gun", 2);
            RayGun     red      = new RayGun("red ray gun", 4);
            SpaceArmor titanium = new SpaceArmor("titanium space armor", 50);
            SpaceArmor alien    = new SpaceArmor("alien tech space armor", 100);
            GravBoots  nike     = new GravBoots("Nike grav boots", 2);
            GravBoots  adidas   = new GravBoots("Adidas grav boots", 4);
            AlienText  romulan  = new AlienText("book of Romulan wisdom", 2);
            AlienText  vulcan   = new AlienText("book of Vulcan wisdom", 4);

            IEquipable[] treasure = new IEquipable[8] {
                green, red, titanium, alien, nike, adidas, romulan, vulcan
            };

            ConsoleYellow("********NINJAS IN SPACE********");

            Hero player = PlayerSetup();

            ConsoleYellow($"You, {player.Name}, have been chosen(randomly selected) to join a team of developer ninjas on a space quest!  To seek out new algorithms, new data structures, and go where no else wants to go! DEEP SPACE!!!\n\nHere you will encounter aliens, space monsters, and the unknown to bring back algorithms to benefit all humans. You now must choose your team.\n\nPress Enter to Start");

            ConsoleKey key = Console.ReadKey(true).Key;

            while (key != ConsoleKey.Enter)
            {
                key = Console.ReadKey(true).Key;
            }
            Console.WriteLine("Please select two crew members");

            Hero teammate1 = TeamSetup();
            Hero teammate2 = TeamSetup();

            List <Hero> party = new List <Hero>()
            {
                player, teammate1, teammate2
            };

            int planet = 0;

            while (planet < 5)
            {
                Console.WriteLine("");
                ConsoleYellow($"Welcome to Planet {planet+1}!");
                ConsoleYellow("=====================");
                List <Enemy> enemies = new List <Enemy>();

                Spider    enemy1 = new Spider("Space Spider 1");
                Zombie    enemy2 = new Zombie("Space Zombie 1");
                Xenomorph enemy3 = new Xenomorph("Xenomorph 1");
                enemies.Add(enemy1);
                enemies.Add(enemy2);
                enemies.Add(enemy3);

                Random die   = new Random();
                int    round = 0;
                while (SumHealthParty(party) > 0 && SumHealthEnemies(enemies) > 0)
                {
                    int turn = round % 6;
                    if (turn >= 0 && turn < 3)
                    {
                        if (party[turn].Health > 0)
                        {
                            Console.WriteLine("");
                            EncounterStatus(party, enemies);
                            if (party[turn] is Ninja)
                            {
                                Ninja ninjaClone = (Ninja)party[turn];
                                Console.WriteLine($"{ninjaClone.Name}'s turn. (A)ttack or (B)ackstab?");
                                string Action = Console.ReadLine();
                                Console.WriteLine($"Target? (1){enemies[0].Name} (2){enemies[1].Name} (3){enemies[2].Name}");
                                string Target = Console.ReadLine();
                                if (Action == "A")
                                {
                                    ninjaClone.Attack(enemies[int.Parse(Target) - 1]);
                                }
                                else if (Action == "B")
                                {
                                    ninjaClone.Backstab(enemies[int.Parse(Target) - 1]);
                                }
                                else if (Action == "Z")
                                {
                                    enemies[int.Parse(Target) - 1].Health = 0;
                                    Console.WriteLine("Let's get this over with");
                                    Console.WriteLine("");
                                }
                            }
                            else if (party[turn] is Samurai)
                            {
                                Samurai samuraiClone = (Samurai)party[turn];
                                Console.WriteLine($"{samuraiClone.Name}'s turn. (A)ttack or (M)editate?");
                                string Action = Console.ReadLine();
                                if (Action == "A")
                                {
                                    Console.WriteLine($"Target? (1){enemies[0].Name} (2){enemies[1].Name} (3){enemies[2].Name}");
                                    string Target = Console.ReadLine();
                                    samuraiClone.Attack(enemies[int.Parse(Target) - 1]);
                                }
                                else if (Action == "M")
                                {
                                    samuraiClone.Meditate();
                                }
                                else if (Action == "Z")
                                {
                                    Console.WriteLine($"Target? (1){enemies[0].Name} (2){enemies[1].Name} (3){enemies[2].Name}");
                                    string Target = Console.ReadLine();
                                    enemies[int.Parse(Target) - 1].Health = 0;
                                    Console.WriteLine("Let's get this over with");
                                    Console.WriteLine("");
                                }
                            }
                            else if (party[turn] is Wizard)
                            {
                                Wizard wizardClone = (Wizard)party[turn];
                                Console.WriteLine($"{wizardClone.Name}'s turn. (A)ttack or (S)hield?");
                                string Action = Console.ReadLine();
                                if (Action == "A")
                                {
                                    Console.WriteLine($"Target? (1){enemies[0].Name} (2){enemies[1].Name} (3){enemies[2].Name}");
                                    string Target = Console.ReadLine();
                                    wizardClone.Attack(enemies[int.Parse(Target) - 1]);
                                }
                                else if (Action == "S")
                                {
                                    Console.WriteLine($"Target? (1){party[0].Name} (2){party[1].Name} (3){party[2].Name}");
                                    string Target = Console.ReadLine();
                                    wizardClone.Shield(party[int.Parse(Target) - 1]);
                                }
                                else if (Action == "Z")
                                {
                                    Console.WriteLine($"Target? (1){enemies[0].Name} (2){enemies[1].Name} (3){enemies[2].Name}");
                                    string Target = Console.ReadLine();
                                    enemies[int.Parse(Target) - 1].Health = 0;
                                    Console.WriteLine("Let's get this over with");
                                    Console.WriteLine("");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (enemies[turn - 3].Health > 0)
                        {
                            Console.WriteLine("");
                            EncounterStatus(party, enemies);
                            if (enemies[turn - 3] is Zombie)
                            {
                                Zombie zombieClone = (Zombie)enemies[turn - 3];
                                Console.WriteLine($"{zombieClone.Name}'s turn.");
                                Random rand     = new Random();
                                bool   attacked = false;
                                while (!attacked)
                                {
                                    int target = rand.Next(3);
                                    if (party[target].Health > 0)
                                    {
                                        zombieClone.Attack(party[target]);
                                        attacked = true;
                                    }
                                }
                                Console.WriteLine("Please press \"Enter\" to continue");
                                string Action = Console.ReadLine();
                            }
                            else if (enemies[turn - 3] is Spider)
                            {
                                Spider spiderClone = (Spider)enemies[turn - 3];
                                Console.WriteLine($"{spiderClone.Name}'s turn.");
                                Random rand     = new Random();
                                bool   attacked = false;
                                while (!attacked)
                                {
                                    int target = rand.Next(3);
                                    if (party[target].Health > 0)
                                    {
                                        spiderClone.Attack(party[target]);
                                        attacked = true;
                                    }
                                }
                                Console.WriteLine("Please press \"Enter\" to continue");
                                string Action = Console.ReadLine();
                            }
                            else if (enemies[turn - 3] is Xenomorph)
                            {
                                Xenomorph xenoClone = (Xenomorph)enemies[turn - 3];
                                Console.WriteLine($"{xenoClone.Name}'s turn.");
                                Random rand     = new Random();
                                bool   attacked = false;
                                while (!attacked)
                                {
                                    int target = rand.Next(3);
                                    if (party[target].Health > 0)
                                    {
                                        xenoClone.Attack(party[target]);
                                        attacked = true;
                                    }
                                }
                                Console.WriteLine("Please press \"Enter\" to continue");
                                string Action = Console.ReadLine();
                            }
                        }
                    }
                    if (SumHealthEnemies(enemies) <= 0)
                    {
                        Console.WriteLine("All enemies vanquished! Congratulations!");
                        int        d8            = die.Next(8);
                        IEquipable foundTreasure = treasure[d8];
                        Equipment  equipClone    = (Equipment)foundTreasure;
                        Console.WriteLine($"You found {equipClone.Name}! {equipClone.Desc} Who should equip it?");
                        string choice = "0";
                        while (choice != "1" && choice != "2" && choice != "3")
                        {
                            Console.WriteLine($"Please type the number of the hero you would like to equip:\n1. {party[0].Name}\n2. {party[1].Name}\n3. {party[2].Name}");
                            choice = Console.ReadLine();
                        }
                        switch (choice)
                        {
                        case ("1"):
                            foundTreasure.Equip(party[0]);
                            Console.WriteLine($"{party[0].Name} has equipped the {equipClone.Name}");
                            party[0].ShowStats();
                            Console.WriteLine("");
                            break;

                        case ("2"):
                            foundTreasure.Equip(party[1]);
                            Console.WriteLine($"{party[1].Name} has equipped the {equipClone.Name}");
                            party[1].ShowStats();
                            Console.WriteLine("");
                            break;

                        case ("3"):
                            foundTreasure.Equip(party[2]);
                            Console.WriteLine($"{party[2].Name} has equipped the {equipClone.Name}");
                            party[2].ShowStats();
                            Console.WriteLine("");
                            break;
                        }
                        Console.WriteLine("Onward to the next planet! Good thing you brought clones of everyone!");
                        player.Health    = player.MaxHealth;
                        teammate1.Health = teammate1.MaxHealth;
                        teammate2.Health = teammate2.MaxHealth;
                        Console.WriteLine("");
                        planet++;
                        if (planet == 5)
                        {
                            ConsoleYellow("You've certainly accomplished something! Saved the universe? Sure! Congratulations!");
                        }
                    }
                    if (SumHealthParty(party) <= 0)
                    {
                        ConsoleYellow("Your party was killed in self-defense! Game over!");
                        planet = 5;
                    }
                    round++;
                }
            }
        }