public void Fight() { Warrior w1 = warrior1; Warrior w2 = warrior2; Console.WriteLine("Welcome to the arena!"); Console.WriteLine("Today {0} will battle against {1}! \n", warrior1, warrior2); bool warrior2Starts = (die.roll() <= die.GetSidesCount() / 2); if (warrior2Starts) { w1 = warrior2; w2 = warrior1; } Console.WriteLine("{0} goes first! \n Let the battle begin!", w1); Console.ReadKey(); //fight loop while (warrior1.alive() && warrior2.alive()) { warrior1.Attack(warrior2); Render(); PrintMessage(warrior1.getMessage()); //attack message PrintMessage(warrior2.getMessage()); // defend message warrior2.Attack(warrior1); Render(); PrintMessage(warrior2.getMessage()); // attack message PrintMessage(warrior1.getMessage()); // defend message Console.WriteLine(); } }
/// <summary> /// warrior defended attack method, adds the defense of the warrior plus dice roll and checks if it killed warrior /// </summary> /// <returns>The defend.</returns> /// <param name="hit">Hit.</param> public void Defend(int hit) { int injury = hit - (defense + die.roll()); if (injury > 0) { health -= injury; message = String.Format("{0} defended against the attack but still lost {1} hp", name, injury); if (health <= 0) { health = 0; message += " And died"; } } else { message = String.Format("{0} blocked the hit", name); } setMessage(message); }