static void Fight(ref Player player) { Moster moster = new Moster(); Random r = new Random(); int a = r.Next(1, 4); switch (a) { case 1: { moster.name = "黄皮子"; moster.Hp = 30; moster.ATc = 10; moster.Sb = 10; } break; case 2: { moster.name = "尸蟞"; moster.Hp = 20; moster.ATc = 5; moster.Sb = 10; } break; case 3: { moster.name = "大粽子"; moster.Hp = 50; moster.ATc = 20; moster.Sb = 10; } break; } Console.SetCursorPosition(90, 14); Console.WriteLine("你遭遇了怪物{0}", moster.name); Console.SetCursorPosition(90, 15); Console.WriteLine(" ---回车继续"); Console.ReadLine(); Console.SetCursorPosition(90, 14); Console.WriteLine(" "); Console.SetCursorPosition(90, 15); Console.WriteLine(" "); while (true) { Console.SetCursorPosition(90, 14); Console.WriteLine("{0}对你发起了攻击", moster.name); int x = r.Next(0, 101); if (x > player.Sb) { Console.SetCursorPosition(90, 15); Console.WriteLine("你受到了{0}点伤害---回车键继续", moster.ATc); Console.SetCursorPosition(90, 20); Console.WriteLine("" + player.name); Console.SetCursorPosition(90, 21); Console.WriteLine("生命值 " + player.Hp + " "); Console.SetCursorPosition(90, 22); Console.WriteLine("攻击力 " + player.ATC + " "); Console.SetCursorPosition(90, 23); Console.WriteLine("闪避率 " + player.Sb + " "); Console.ReadLine(); player.Hp -= moster.ATc; if (player.Hp == 0) { Console.SetCursorPosition(90, 14); Console.WriteLine("你死了---回车键继续"); Console.ReadLine(); Console.Clear(); Console.SetCursorPosition(55, 10); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("游 戏 结 束"); Console.ReadLine(); break; } } else { Console.SetCursorPosition(90, 15); Console.WriteLine("被你躲开了---回车键继续"); Console.ReadLine(); } Console.SetCursorPosition(90, 14); Console.WriteLine("按回车键发起进攻"); Console.SetCursorPosition(90, 15); Console.WriteLine(" "); Console.ReadLine(); Console.SetCursorPosition(90, 14); Console.WriteLine(" "); Console.SetCursorPosition(90, 15); Console.WriteLine(" "); Console.SetCursorPosition(90, 14); Console.WriteLine("你发起了攻击"); Console.ReadLine(); int y = r.Next(0, 101); if (y > moster.Sb) { Console.SetCursorPosition(90, 15); Console.WriteLine("怪物受到了{0}点伤害,还剩{1}", player.ATC, moster.Hp); moster.Hp -= player.ATC; Console.ReadLine(); Console.SetCursorPosition(90, 14); Console.WriteLine(" "); Console.SetCursorPosition(90, 15); Console.WriteLine(" "); if (moster.Hp < 0) { Console.SetCursorPosition(90, 14); Console.WriteLine("你赢了"); Console.ReadLine(); break; } } else { Console.SetCursorPosition(90, 15); Console.WriteLine("怪物躲开了"); } Console.SetCursorPosition(90, 14); Console.WriteLine(" "); Console.SetCursorPosition(90, 15); Console.WriteLine(" "); } }
void Start() { //Human Shuibian = new Human("陳水扁", 58); // Human ChiaWei = new Human("林家緯", 25); Human Shuibian = new Human("亞洲人", 160, "陳水扁", 58); Human ChiaWei = new Human("亞洲人", 180, "林家緯", 25); //ChiaWei.SayMySelf(); Human Kobe = new Human("北美洲人", 198, "摳逼不萊恩特", 39); Human JKRowLing = new Human("JK羅琳"); Human.PassHeight = 200; Kobe.SayMySelf(); JKRowLing.SayMySelf(); Debug.Log(ChiaWei.Talk(Shuibian)); Debug.Log(Shuibian.Talk(ChiaWei)); Debug.Log(Kobe.Talk(ChiaWei)); Debug.Log(JKRowLing.Talk(Kobe)); Debug.Log(Human.SayPassHeight()); Debug.Log(ChiaWei.name + "的身高是否及格:" + ChiaWei.PassforMyHeight()); Human.PassHeight = 170; Debug.Log(Human.SayPassHeight()); Debug.Log(ChiaWei.name + "的身高是否及格:" + ChiaWei.PassforMyHeight()); ABC.ABCC(); //靜態Class Debug.Log(Human.SayThisMethod()); //這個Class裡面的靜態method User MyUser = new User("林家緯", "1233334"); Debug.Log(MyUser.GetUserName()); Debug.Log(MyUser.GetPassword()); Debug.Log(MyUser.Username); MyUser.Username = "******";//向Set存入 Debug.Log(MyUser.Username); ///練習題目 Player player = new Player(); player.pickAGold(); player.HungerRate += 10; // 餓了,飢餓度上升 Debug.Log("飢餓度:" + player.HungerRate); player.pickASilver(); player.HungerRate += 10; // 餓了,飢餓度上升 Debug.Log("飢餓度:" + player.HungerRate); player.pickASilver(); player.HungerRate += 10; // 餓了,飢餓度上升 Debug.Log("飢餓度:" + player.HungerRate + ",身上物品總值:" + player.TotalValue); player.pickACopper(); player.HungerRate -= 60; // 吃了一個可以減少 60 飢餓度的東西 Debug.Log("飢餓度:" + player.HungerRate); player.pickAGold(); player.HungerRate -= 60; // 吃了一個可以減少 60 飢餓度的東西 Debug.Log("飢餓度:" + player.HungerRate + ",身上物品總值:" + player.TotalValue); Moster ms = new Moster(75, "大頭怪", 100); Debug.Log(ms.HP); ms.HP -= 10; Debug.Log(ms.HP); ms.HP += 90; Debug.Log(ms.HP); ms.HP -= 56; Debug.Log(ms.HP); Debug.Log(ms.SayMyname()); Debug.Log(ms.Walk()); Bot bt = new Bot(95, "阿諾", 100); Debug.Log(bt.HP); // bt.InJured(ms.AttAck); ms.AttAck(bt); Debug.Log(bt.HP); ms.SetAttAck = 200; //bt.InJured(ms.AttAck); ms.AttAck(bt); Debug.Log(bt.HP); Debug.Log(bt.SayMyname()); Debug.Log(bt.Walk()); }