class Hero { public int ATN { get; set; } public int DEF { get; set; } public int HP { get; set; } public string Name { get; set; } public bool Attack(Hero target) { bool hasDead = false; Random r = new Random(); int damage = r.Next(this.ATN - target.DEF); target.HP -= damage; Console.WriteLine("{0}向{1}發動攻擊,形成{2}點傷害!", this.Name, target.Name, damage, target.HP); if (target.HP <= 0) { Console.WriteLine("{0}已經死亡!", target.Name); target.HP = 0; hasDead = true; } Console.WriteLine("{0}生命值變爲{1}", target.Name, target.HP); return hasDead; } static void Main() { Hero A = new Hero() { Name = "卡特琳娜", ATN = 100, DEF = 50, HP = 300 }, B = new Hero() { HP = 300, Name = "蓋倫", ATN = 100, DEF = 50 }; Console.WriteLine("---------------------\n 英雄聯盟\n---------------------"); while (A.HP >= 0 && B.HP >= 0) { if (B.Attack(A)) { Console.WriteLine("{0}獲取勝利", B.Name); break; } System.Threading.Thread.Sleep(500); if (A.Attack(B)) { Console.WriteLine("{0}獲取勝利", A.Name); break; } System.Threading.Thread.Sleep(500); } Console.WriteLine("請按任意鍵繼續。。。"); Console.ReadKey(); } }