Ejemplo n.º 1
0
        public void HeroFight()
        {
            bool fight = false;

            while (!fight)
            {
                Console.WriteLine("Hero turn");
                Console.WriteLine("-----------------------------");
                Console.WriteLine();
                Console.WriteLine("Choose the option you want: ");
                Console.WriteLine("Press 1 to show status.");
                Console.WriteLine("Press 2 to show inventory.");
                Console.WriteLine("Press 3 to choose the weapon.");
                Console.WriteLine("Press 4 to choose the armor.");
                Console.WriteLine("Press 5 to buy health.");
                Console.WriteLine("Press 0 to quit the fight.");
                Console.WriteLine("Press any key to fight directly.");
                char inputValue = Console.ReadKey().KeyChar;
                Console.WriteLine();

                if (inputValue == '0')
                {
                    Hero.CurrentHealth    = Hero.OriginalHealth;
                    Monster.CurrentHealth = Monster.OriginalHealth;
                    throw new Exception("You quit the fight.");
                }
                else if (inputValue == '1')
                {
                    Hero.ShowStats();

                    fight = false;
                }
                else if (inputValue == '2')
                {
                    Hero.ShowInventory();

                    fight = false;
                }
                else if (inputValue == '3')
                {
                    Hero.GetWeapon();

                    fight = false;
                }
                else if (inputValue == '4')
                {
                    Hero.GetArmor();
                    fight = false;
                }
                else if (inputValue == '5')
                {
                    Hero.BuyHealth();
                }
                else
                {
                    fight = true;
                }
            }
            int lostHealth = 0;

            if (Hero.EquippedWeapon == null)
            {
                lostHealth = Hero.Strength - Monster.Defense;
            }
            else
            {
                lostHealth = Hero.Strength + Hero.EquippedWeapon.Power - Monster.Defense;
            }

            if (lostHealth <= 0)
            {
                lostHealth = 0;
            }
            Monster.CurrentHealth -= lostHealth;

            Console.WriteLine();
            Console.WriteLine("Your attack made the monstor lose {0} health.", lostHealth);
            Console.WriteLine();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            try
            {
                Console.WriteLine("Welcome to the game, please input your name...");

                Player = Console.ReadLine();
                Console.WriteLine("Welcome {0}, the game is starting...", Player);

                // Choose hero module.
                Console.WriteLine("---------------------------------------");
                Console.WriteLine();
                if (Heroes.Count == 0)
                {
                    throw new Exception("No hero in the game, cannot play, quit the game...");
                }

                Console.WriteLine("Choose one hero or get a random one.");
                Console.WriteLine("Press 0 to quit the Game.");

                Hero chosenHero = ChooseHero();
                Console.WriteLine("---------------------------------------");
                Console.WriteLine();

                bool stillGame = true;
                while (stillGame)
                {
                    // Choose monster module
                    if (Monsters.Count == 0)
                    {
                        throw new Exception("No monster in the game, cannot play, quit the game...");
                    }

                    Console.WriteLine("Choose one monster or get a random one.");
                    Console.WriteLine("Press 0 to quit the Game.");

                    Monster chosenMonster = ChooseMonster();

                    Console.WriteLine("---------------------------------------");
                    Console.WriteLine();

                    // Main menu to switch statements.
                    bool inMenu = true;
                    while (inMenu)
                    {
                        Console.WriteLine("Press 0 to quit the Game.");
                        Console.WriteLine("Press 1 to show the statistics.");
                        Console.WriteLine("Press 2 to show the inventory.");
                        Console.WriteLine("Press 3 to select the weapons.");
                        Console.WriteLine("Press 4 to select the armors.");
                        Console.WriteLine("Press any key to FIGHT.");

                        char statValue = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        try
                        {
                            if (int.Parse(statValue.ToString()) == 0)
                            {
                                throw new Exception("You quit the Game...");
                            }
                            else if (int.Parse(statValue.ToString()) == 1)
                            {
                                chosenHero.ShowStats();
                                inMenu = true;
                            }
                            else if (int.Parse(statValue.ToString()) == 2)
                            {
                                chosenHero.ShowInventory();
                                inMenu = true;
                            }
                            else if (int.Parse(statValue.ToString()) == 3)
                            {
                                // Select weapons.
                                Console.WriteLine("Choose the weapons for the hero...");
                                GetWeapons(chosenHero);
                                inMenu = true;
                            }
                            else if (int.Parse(statValue.ToString()) == 4)
                            {
                                // Select armors.
                                Console.WriteLine("Choose the armors for the hero...");
                                GetArmors(chosenHero);
                                inMenu = true;
                            }
                            else
                            {
                                Console.WriteLine("Quiting from the menu, you can fight now.");
                                inMenu = false;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Quiting from the menu, you can fight now.");
                            inMenu = false;
                        }
                    }

                    // Fight module.
                    Console.WriteLine("You are joining a fight now...");
                    Fight fight = new Fight(chosenHero, chosenMonster);
                    Fights.Add(fight);
                    fight.FightStart();
                    Console.WriteLine("----------------------------");
                    Console.WriteLine();

                    Console.WriteLine("Do you want to start a new game?");
                    Console.WriteLine("Press Y to start, any other key to quit the game.");
                    char input = Console.ReadKey().KeyChar;
                    Console.WriteLine();
                    if (input == 'Y' || input == 'y')
                    {
                        stillGame = true;
                    }
                    else
                    {
                        stillGame = false;
                    }
                }
                Console.WriteLine("You are quiting the game, bye!");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }