Exemple #1
0
        static void Main(string[] args)
        {
            Console.Write("Player Name: ");
            Player player = new Player(Console.ReadLine());
            Orc    orc    = new Orc();
            bool   end    = false;

            // Preparations:
            bool stun_active   = false;
            bool debuff_active = false;

            while (end == false)
            {
                // Player Move:
Fail:
                Console.Write(">");
                string command = Console.ReadLine();

                if (command.ToLower() == "attack")
                {
                    player.Attack(orc);
                    PlayerAttackSound();
                    Thread.Sleep(2000);
                }
                else if (command.ToLower() == "fireball")
                {
                    if (player.mana - player.costF >= 0)
                    {
                        player.Fireball(orc);
                        PlayerFireballSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed Fireball spell due to lack of mana.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "might")
                {
                    if (player.mana - player.costM >= 0)
                    {
                        player.Might();
                        PlayerMightSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed Might spell due to lack of mana.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "stun")
                {
                    if (player.mana - player.costS >= 0)
                    {
                        player.Stun(orc);
                        stun_active = true;
                        PlayerStunSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed Stun spell due to lack of mana.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "debuff")
                {
                    if (player.mana - player.costD >= 0)
                    {
                        player.Debuff(orc);
                        debuff_active = true;
                        PlayerDebuffSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed Debuff spell due to lack of mana.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "health potion")
                {
                    if (player.healthPotions > 0)
                    {
                        player.HealthPotion();
                        player.healthPotions--;
                        PlayerPotionSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed to drink health potion due to lack of such an item.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "mana potion")
                {
                    if (player.manaPotions > 0)
                    {
                        player.ManaPotion();
                        player.manaPotions--;
                        PlayerPotionSound();
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        Console.WriteLine("{0} failed to drink mana potion due to lack of such an item.", player.name);
                        Thread.Sleep(2000);
                    }
                }
                else if (command.ToLower() == "stats")
                {
                    // Stats:
                    Console.WriteLine("{0}: HP = {1}, ATK = {2}, MP = {3}", player.name, player.health, player.attack, player.mana);
                    Console.WriteLine("Orc:    HP = {0}, ATK = {1}, MP = {2}", orc.health, orc.attack, orc.mana);
                    Console.WriteLine(new string('-', 25));
                    goto Fail;
                }
                else if (command.ToLower() == "rules")
                {
                    // Open "Game Rules.txt" file:
                    ReadRules();
                    PlayRulesSound();
                    Console.WriteLine(new string('-', 25));
                    goto Fail;
                }
                else
                {
                    Console.WriteLine("Unknown command, try again!");
                    Console.WriteLine(new string('-', 25));
                    goto Fail;
                }

                // Extra effects from spells:
                if (debuff_active == true && player.durationD > 0)
                {
                    player.durationD--;
                }
                else
                {
                    debuff_active = false;
                    orc.attack    = 20;
                }

                if (stun_active == true && player.durationS > 0)
                {
                    player.durationS--;
                }
                else
                {
                    stun_active    = false;
                    orc.can_attack = true;
                }

                // Orc Move:
                orc.Attack(player);
                if (orc.can_attack != false)
                {
                    if (orc.crit == true)
                    {
                        OrcAttackCritSound();
                        System.Threading.Thread.Sleep(2000);
                        orc.crit = false;
                    }
                    else
                    {
                        OrcAttackSound();
                        System.Threading.Thread.Sleep(2000);
                    }
                }

                // End
                if (orc.health <= 0)
                {
                    Console.WriteLine("WINNER: " + player.name);
                    PlayVictorySound();
                    Thread.Sleep(10000);
                    end = true;
                }
                else if (player.health <= 0)
                {
                    Console.WriteLine("WINNER: Orc");
                    PlayDefeatSound();
                    Thread.Sleep(1000);
                    end = true;
                }
            }
        }