Пример #1
0
        /// <summary>
        /// Runs a battle between a Hero and a Dragon. Ends when one of them has 0 HitPoints.
        /// </summary>
        /// <param name="hero">The Hero in the battle.</param>
        /// <param name="enemy">The Dragon in the battle.</param>
        static void Battle(Hero hero, Dragon enemy)
        {
            // TODO++: modify Battle to take a List<Dragon> of enemies, and have each of them attack every time through the loop.
            // You may want to have the Hero automatically attack the first enemy in the list that is still alive.
            Die myDie = new Die(20);

            Console.WriteLine(MyHero);

            Console.WriteLine("VERSUS");

            Console.WriteLine(MyEnemy);


            while (MyHero.IsAlive())
            {
                int attackRoll = myDie.Roll();
                Console.WriteLine("Rolled {0} for attack phase", attackRoll);
                MyHero.Attack(MyEnemy, attackRoll);
                Console.WriteLine(MyEnemy);

                if (!MyEnemy.IsAlive())
                {
                    Console.WriteLine("{0} slayed {1}!", MyHero.Name, MyEnemy.Name);
                    break;
                }
                int defenseRoll = myDie.Roll();
                Console.WriteLine("Rolled {0} for defense phase", defenseRoll);
                MyHero.Defend(MyEnemy, defenseRoll);
                Console.WriteLine(MyHero);
            }

            if (!MyHero.IsAlive())
            {
                Console.WriteLine("{0} was defeated by {1}. :(", MyHero.Name, MyEnemy.Name);
            }
        }
Пример #2
0
 /// <summary>
 /// Runs a defend phase for the Hero.
 /// <para>Damage is calculated by taking the opponent's <see cref="Dragon.Offense"/>, subtracting the <paramref name="diceRoll"/> parameter, and subtracting the Hero's <see cref="Defense"/>.</para>
 /// <para>The damage must be zero or positive - if it is calculated to be negative using the above formula, no damage is dealt.</para>
 /// <para>If the <paramref name="diceRoll"/> is 1, the defense is a critical failure and the Hero takes damage equal to the Dragon's <see cref="Dragon.Offense"/>, regardless of the above calculations.</para> If the <paramref name="diceRoll"/> is 20, the attack is blocked and the Hero receives zero damage, regardless of the above calculations.</para>
 /// <para>After damage is calculated according to the above rules, the Hero receives the damage by having that amount subtracted from the Hero's <see cref="HitPoints"/></para>
 /// </summary>
 /// <param name="opponent">The Dragon to attack</param>
 /// <param name="diceRoll">A number (1-20) from a dice roll, relating to the effectiveness of the block</param>
 public void Defend(Dragon opponent, int diceRoll)
 {
     // TODO
 }
Пример #3
0
 /// <summary>
 /// Runs an attack phase for the Hero.
 /// <para>Damage is calculated by taking the <paramref name="diceRoll"/> parameter, adding the Hero's <see cref="Offense"/>, and subtracting the <paramref name="opponent"/>'s Defense.</para>
 /// <para>The damage must be zero or positive - if it is calculated to be negative using the above formula, no damage is dealt.</para>
 /// <para>If the <paramref name="diceRoll"/> is 1, the attack fails and the damage dealt is 0, regardless of the above calculations.</para> If the <paramref name="diceRoll"/> is 20, the attack is a critical hit and automatically succeeds with a value that is three times the Hero's "natural" <see cref="Offense"/>.</para>
 /// <para>After damage is calculated according to the above rules, the Dragon receives the damage by having that amount subtracted from the Dragon's <see cref="Dragon.HitPoints"/></para>
 /// </summary>
 /// <param name="opponent">The Dragon to attack</param>
 /// <param name="diceRoll">A number (1-20) from a dice roll, relating to the effectiveness of the attack</param>
 public void Attack(Dragon opponent, int diceRoll)
 {
     // TODO
 }