Exemple #1
0
        public void StartBattle(Player player, Enemy randomEnemy)
        {
            if (!randomEnemy.IsDead())
            {
                Console.Clear();
                Console.WriteLine(border);
                Console.WriteLine("||         FIGHTING ENEMY           ");
                Console.WriteLine(border);

                Console.WriteLine("|| {0} appears!", randomEnemy.GetName());
                Console.WriteLine(border);
                Console.Write("|| Element: ");
                Console.ForegroundColor = randomEnemy.GetElementColor();
                Console.Write("{0}", randomEnemy.GetElementText());
                Console.WriteLine("");
                Console.ResetColor();
                Console.WriteLine(border);
                Console.WriteLine("|| Enemy HP : {0} / {1}", randomEnemy.GetHP(), randomEnemy.GetMaxHP());

                if (randomEnemy.GetEnemyType() == 2)
                {
                    Console.WriteLine("|| Enemy Mana : {0} / {1}", randomEnemy.GetMana(), randomEnemy.GetMaxMana());
                }

                Console.WriteLine(border);
                Console.Write("|| Player HP: ");
                Console.ForegroundColor = player.GetHPColor();
                Console.Write("{0} / {1}", player.GetHealth(), player.GetMaxHealth());
                Console.WriteLine("");
                Console.ResetColor();
                Console.WriteLine("|| Player Mana: {0} / {1}   ", player.GetMana(), player.GetMaxMana());
                Console.WriteLine(border);
                Console.WriteLine("|| What will you do?");
                Console.WriteLine("|| [1] Attack");
                Console.WriteLine("|| [2] Use Skill");
                Console.WriteLine("|| [3] Use Item");
                Console.WriteLine(border);

                string input = Console.ReadLine();
                int    slot;

                if (Int32.TryParse(input, out slot))
                {
                    slot = Convert.ToInt32(input);
                }
                else
                {
                    Console.WriteLine("Pls enter a valid number!");
                    Console.ReadLine();
                    StartBattle(player, randomEnemy);
                }
                if (input == "1")
                {
                    if (player.GetSpeed() > randomEnemy.GetSpeed())
                    {
                        Attack(player.Attack(), 1, null, player, randomEnemy);
                        if (!randomEnemy.IsDead())
                        {
                            EnemyAttack(player, randomEnemy);
                        }
                        if (player.IsDead())
                        {
                            GameOver();
                        }
                        Console.WriteLine("|| Press Enter to Continue");

                        Console.ReadLine();
                        StartBattle(player, randomEnemy);
                    }
                    else
                    {
                        if (!randomEnemy.IsDead())
                        {
                            EnemyAttack(player, randomEnemy);
                        }
                        if (player.IsDead())
                        {
                            GameOver();
                        }
                        else
                        {
                            Attack(player.Attack(), 1, null, player, randomEnemy);
                        }

                        Console.WriteLine("|| Press Enter to Continue");

                        Console.ReadLine();
                        if (gameOver)
                        {
                            return;
                        }
                        else
                        {
                            StartBattle(player, randomEnemy);
                        }
                    }
                }
                else if (input == "2")
                {
                    ChooseSkill(player, randomEnemy);
                }
                else if (input == "3")
                {
                    ChooseItem(player, randomEnemy);
                }
                else if (input == "9")
                {
                    Attack(99999, 1, null, player, randomEnemy);
                    Console.WriteLine("|| Press Enter to Continue");

                    Console.ReadLine();
                    StartBattle(player, randomEnemy);
                }
                else
                {
                    Console.WriteLine("|| Pls enter a Valid number.");
                    StartBattle(player, randomEnemy);
                }
            }
            else
            {
                Console.Clear();
                if (randomEnemy.GetKillCount() <= 0)
                {
                    Console.WriteLine(border);
                    Console.WriteLine("||            VICTORY          ");
                    Console.WriteLine(border);

                    randomEnemy.SetKillCount(randomEnemy.GetKillCount() + 1);
                    player.GainExperience(randomEnemy.GetXP());
                    player.AddGold(randomEnemy.GetGold());
                    won      = true;
                    gameOver = false;

                    Console.WriteLine("|| You got {0} Gold!", randomEnemy.GetGold());
                    Console.WriteLine("|| You got {0} Experience!", randomEnemy.GetXP());
                    if (randomEnemy.ItemDropped())
                    {
                        Item it = randomEnemy.GetDroppedItem();
                        player.AddToInventory(it, it.GetAmount());
                        Console.WriteLine("|| You got {0}x {1}!", it.GetAmount(), it.GetName());
                    }
                    if (player.LevelUp())
                    {
                        Console.WriteLine(border);
                        Console.WriteLine("|| You leveled up!");
                        Console.WriteLine("|| You are now Level {0} !", player.level);
                        player.CheckForNewSkills(sm);
                        Console.WriteLine("|| Choose a Stat to Level up!");
                        Console.WriteLine(border);

                        string stam = "Increases your Max HP";
                        string def  = "Reduces normal damage taken";
                        string str  = "Increases physical damage dealt";
                        string inte = "Increases elemental damage dealt and your maximum Mana";
                        string spd  = "If you have more speed than your enemy, you attack first";

                        Console.WriteLine(String.Format("|| [1] Stamina - {0,10}", stam));
                        Console.WriteLine(String.Format("|| [2] Defense  - {0,10}", def));
                        Console.WriteLine(String.Format("|| [3] Strength  - {0,10}", str));
                        Console.WriteLine(String.Format("|| [4] Intelligence  - {0,10}", inte));
                        Console.WriteLine(String.Format("|| [5] Speed  - {0,10}", spd));
                        Console.WriteLine(border);

LevelUp:
                        string input = Console.ReadLine();
                        if (input == "1")
                        {
                            Console.WriteLine("|| Stamina increased by 1. Max Health increased!");
                            player.ChooseStat(input);
                        }
                        else if (input == "2")
                        {
                            Console.WriteLine("|| Defense increased by 1!");
                            player.ChooseStat(input);
                        }
                        else if (input == "3")
                        {
                            Console.WriteLine("|| Strength increased by 1!");
                            player.ChooseStat(input);
                        }
                        else if (input == "4")
                        {
                            Console.WriteLine("|| Intelligence increased by 1. Max Mana increased!");
                            player.ChooseStat(input);
                        }
                        else if (input == "5")
                        {
                            Console.WriteLine("|| Speed increased by 1.");
                            player.ChooseStat(input);
                        }
                        else
                        {
                            goto LevelUp;
                        }
                    }

                    Console.WriteLine(border);
                    Console.WriteLine("|| Press Enter to return to the Main Menu");
                }
                else
                {
                    Console.WriteLine(border);
                    Console.WriteLine("|| No enemies are nearby...");
                    Console.WriteLine(border);
                    Console.WriteLine("|| Press Enter to return to the Main Menu");
                }

                Console.ReadLine();
                EndBattle();
            }
        }