Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Calls the actions the player specified.
        /// </summary>
        /// <param name="action">Action entered by player</param>
        /// <returns>True if game continues, false if game ended</returns>
        private bool PlayGameAction(int action)
        {
            switch (action)
            {
            case 1:
                Hero opponent = CreateRandomOpponent(PlayerHero.Level);

                // Characters get a luck bonus on their DPS between 0 and 20%
                var    rand          = new Random();
                double herosLuck     = rand.NextDouble() * (1.2 - 1.0) + 1.0;
                double opponentsLuck = rand.NextDouble() * (1.2 - 1.0) + 1.0;

                Fight(PlayerHero, opponent, herosLuck, opponentsLuck);
                break;

            case 2:
                PlayerHero.DisplayStats();
                break;

            default:
            case 3:
                GameWriter.EndGameMessage(PlayerHero.Name);
                return(false);
            }

            return(true);
        }