static void Main(string[] args) { RollingDie die = new RollingDie(); RollingDie die2 = new RollingDie(10); Console.WriteLine(die); for (int i = 0; i < 10; i++) { Console.WriteLine(die.Roll() + " "); } //Console.WriteLine(die.GetSidesCount()); //Console.WriteLine(die.Roll()); //Console.WriteLine(die.Roll()); Console.WriteLine(die2); for (int i = 0; i < 10; i++) { Console.WriteLine(die2.Roll() + " "); } //Console.WriteLine(die2.GetSidesCount()); //Console.WriteLine(die2.Roll()); //Console.WriteLine(die2.Roll()); Console.ReadLine(); }
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); }
public void Defend(int hit) { int injury = hit - (defense + die.Roll()); //hit - defense + die roll = damage amount if (injury > 0) //if injury is more than 0 health with subtract by injury amount { health -= injury; message = String.Format("{0} defended against the attack but still lost {1} hp", name, injury); if (health <= 0) //cleaning up for negative health to == zero { health = 0; message += " and died;"; } } else { message = String.Format("{0} blocked the hit", name); } SetMessage(message); }
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. \nLet the battle begin...", w1); Console.ReadKey(); while (w1.Alive() && w2.Alive()) { w1.Attack(w2); Render(); PrintMessage(w1.GetMessage()); PrintMessage(w2.GetMessage()); Console.ReadKey(); if (w2.Alive()) { w2.Attack(w1); Render(); PrintMessage(w2.GetMessage()); PrintMessage(w1.GetMessage()); Console.ReadKey(); } } }