예제 #1
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        public void Play()
        {
            GameWriter.WelcomeMessage();

            int    heroType = GameReader.GetHeroType();
            string name     = GameReader.GetHeroName(MaxLengthOfName);

            PlayerHero = CreateHero(heroType, name);

            int action;

            do
            {
                action = GameReader.GetGameAction();
            } while (PlayGameAction(action));
        }
예제 #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;
            }
        }