Exemplo n.º 1
0
        /// <summary>
        /// Handles a fight between two Heroes. When the fight is lost, the game ends. When the fight is won, the player gets a random item and levels up.
        /// </summary>
        /// <param name="hero">The opponent</param>
        private static void Fight(Hero hero, Hero opponent, double herosLuck, double opponentsLuck)
        {
            GameWriter.OpponentDescriptionMessage(opponent.GetType().Name, opponent.DPS);

            GameWriter.PressKeyToContinue();

            if (hero.DPS * herosLuck < opponent.DPS * opponentsLuck)
            {
                GameWriter.GameLostMessage();
                GameWriter.EndGameMessage(hero.Name);
                Environment.Exit(0);
                return;
            }

            GameWriter.GameWonMessage();

            GameWriter.PressKeyToContinue();

            hero.LevelUp(1);
            GameWriter.LevelUpMessage(hero.Level);

            GameWriter.PressKeyToContinue();

            HandleFoundItem(hero);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new random item and asks the player what they want to do with it.
        /// </summary>
        /// <param name="hero">The players hero</param>
        private static void HandleFoundItem(Hero hero)
        {
            Item   item       = CreateRandomItem();
            string typeOfItem = item.GetType().Name;

            GameWriter.ItemFoundMessage(item.ItemDescription());

            switch (GameReader.GetFoundItemAction())
            {
            case 1:
                try
                {
                    string typeOfWeapon = new Weapon().GetType().Name;

                    if (typeOfItem.Equals(typeOfWeapon))
                    {
                        hero.Equip((Weapon)item);
                    }
                    else
                    {
                        hero.Equip((Armor)item);
                    }

                    GameWriter.ItemEquippedMessage(typeOfItem);
                    GameWriter.PressKeyToContinue();
                }
                catch (Exception e)
                {
                    GameWriter.ItemEquippedErrorMessage(e.Message);
                    GameWriter.PressKeyToContinue();
                }
                break;

            default:
                break;
            }
        }