public void Attack(warrior enemy) { int damage = weapon.Damage / enemy.armor.ArmorPoint; enemy.health -= damage; AttackResult(enemy, damage); Thread.Sleep(200); }
private void AttackResult(warrior enemy, int damage) { if (enemy.health <= 0) { enemy.isAlive = false; Tools.ColorfulWriteLine($"{enemy.name} is dead!", ConsoleColor.Red); Tools.ColorfulWriteLine($"{name} is victorious!", ConsoleColor.Yellow); } else { Console.WriteLine($"{name} attacked {enemy.name}. \n{damage} was infilicted to {enemy.name}, remaining health of {enemy.health} is {enemy.health} "); Console.WriteLine("--------------------------------------------------------------------------"); } }
static void Main(string[] args) { warrior goodGuy = new warrior("Justice", Faction.goodGuy); warrior badGuy = new warrior("Evil", Faction.badGuy); while (goodGuy.IsAlive && badGuy.IsAlive) { if (rng.Next(0, 10) < 5) { goodGuy.Attack(badGuy); } else { badGuy.Attack(goodGuy); } } Console.ReadKey(); }