首页 > 代码库 > 练习——对战游戏
练习——对战游戏
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 对战 { class Program { static void Main(string[] args) { role rol1 = new role(); role rol2 = new role(); skill s1 = new skill(); skill s2 = new skill(); skill s3 = new skill(); skill s4 = new skill(); Random ran= new Random(); Console.WriteLine("1、格罗姆 2、吉安娜 3、乌瑟尔 4、安度因"); int r1 = 0; int r2 = 0; for (; ; )//选择角色 { try { Console.Write("请选择第一个角色(输入序号):"); int rr1 = int.Parse(Console.ReadLine()); if (rr1 >= 1 && rr1 <= 4) { r1 = rr1; } else { Console.WriteLine("请从以上四个角色之中选择!"); continue; } Console.Write("请选择第二个角色(输入序号):"); int rr2 = int.Parse(Console.ReadLine()); if (rr2 >= 1 && rr2 <= 4) { r2 = rr2; break; } else { Console.WriteLine("请从以上四个角色之中选择!"); continue; } } catch { Console.WriteLine("操作有误,请正确输入角色序号!"); continue; } } //录入第一个角色信息 if(r1==1) { rol1.Name = "格罗姆"; rol1.Blood = 3000; rol1.Str = 100; s1.Name = "冲锋"; s1.Str = 200; rol1.Smlski = s1; s2.Name = "风车"; s2.Str = 500; rol1.Bigski = s2; } else if (r1 == 2) { rol1.Name = "吉安娜"; rol1.Blood = 1500; rol1.Str = 200; s1.Name = "火球术"; s1.Str = 400; rol1.Smlski = s1; s2.Name = "暴风雪"; s2.Str = 1000; rol1.Bigski = s2; } else if (r1 == 3) { rol1.Name = "乌瑟尔"; rol1.Blood = 2500; rol1.Str = 90; s1.Name = "圣光术"; s1.Str = 300; rol1.Smlski = s1; s2.Name = "圣疗术"; s2.Str = -600; rol1.Bigski = s2; } else { rol1.Name = "安度因"; rol1.Blood = 2000; rol1.Str = 80; s1.Name = "治疗术"; s1.Str = -200; rol1.Smlski = s1; s2.Name = "医疗波"; s2.Str = -800; rol1.Bigski = s2; } //录入第二个角色信息 if (r2 == 1) { rol2.Name = "格罗姆"; rol2.Blood = 3000; rol2.Str = 100; s3.Name = "冲锋"; s3.Str = 200; rol2.Smlski = s3; s4.Name = "风车"; s4.Str = 500; rol2.Bigski = s4; } else if (r2 == 2) { rol2.Name = "吉安娜"; rol2.Blood = 1500; rol2.Str = 200; s3.Name = "火球术"; s3.Str = 400; rol2.Smlski = s3; s4.Name = "暴风雪"; s4.Str = 1000; rol2.Bigski = s4; } else if (r2 == 3) { rol2.Name = "乌瑟尔"; rol2.Blood = 2500; rol2.Str = 90; s3.Name = "圣光术"; s3.Str = 300; rol2.Smlski = s3; s4.Name = "圣疗术"; s4.Str = -600; rol2.Bigski = s4; } else { rol2.Name = "安度因"; rol2.Blood = 2000; rol2.Str = 80; s3.Name = "治疗术"; s3.Str = -200; rol2.Smlski = s3; s4.Name = "医疗波"; s4.Str = -800; rol2.Bigski = s4; } if(rol1.Name==rol2.Name) { rol1.Name = rol1.Name + "1"; rol2.Name = rol2.Name + "2"; } Console.WriteLine("=========================================================="); Console.WriteLine("角色"+"\t"+"生命值"+"\t"+"攻击力"+"\t"+"技能1"+"\t"+"技能2"); Console.WriteLine(rol1.Name + "\t" + rol1.Blood + "\t" + rol1.Str + "\t" + rol1.Smlski.Name + "\t" + rol1.Bigski.Name); Console.WriteLine(rol2.Name + "\t" + rol2.Blood + "\t" + rol2.Str + "\t" + rol2.Smlski.Name + "\t" + rol2.Bigski.Name); Console.WriteLine("选择完毕,请按任意键开始战斗!"); Console.ReadKey(); //开始战斗 for (; ; ) { //默认角色1先手攻击 int ran1 = ran.Next(1, 101);//判断是否释放技能 if(ran1<=5)//释放大技能 { int bigstr=0;//记录大技能数值 //判断是否是治疗技能 if (rol1.Bigski.Str > 0) { bigstr = ran.Next(((rol1.Bigski.Str) / 10) * 8, ((rol1.Bigski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol1.Name, rol1.Bigski.Name, rol2.Name, bigstr, rol2.Name, (rol2.Blood - bigstr)); rol2.Blood -= bigstr; } else { bigstr = ran.Next((Math.Abs(rol1.Bigski.Str) / 10) * 8, (Math.Abs(rol1.Bigski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol1.Name, rol1.Bigski.Name, bigstr, rol1.Name, (rol1.Blood + bigstr)); rol1.Blood += bigstr; } } else if (ran1<= 20)//释放小技能 { int smlstr = 0; if (rol1.Smlski.Str > 0) { smlstr = ran.Next(((rol1.Smlski.Str) / 10) * 8, ((rol1.Smlski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆{1}☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol1.Name, rol1.Smlski.Name, rol2.Name, smlstr, rol2.Name, (rol2.Blood - smlstr)); rol2.Blood -= smlstr; } else { smlstr = ran.Next((Math.Abs(rol1.Smlski.Str) / 10) * 8, (Math.Abs(rol1.Smlski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆{1}☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol1.Name, rol1.Smlski.Name, smlstr, rol1.Name, (rol1.Blood + smlstr)); rol1.Blood += smlstr; } } else//不释放技能,普通攻击 { int str = ran.Next(((rol1.Str) / 10) * 8, ((rol1.Str) / 10) * 12); Console.WriteLine("【{0}】攻击了【{1}】,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}",rol1.Name,rol2.Name,rol2.Name,str,rol2.Name,(rol2.Blood-str)); rol2.Blood -= str; } Console.WriteLine(); if(rol2.Blood<=0)//判断是否阵亡 { Console.WriteLine("【{0}】阵亡,【{1}】获得了胜利。",rol2.Name,rol1.Name); break; } System.Threading.Thread.Sleep(1500); //角色2进行攻击 int ran2 = ran.Next(1, 101); if (ran2 <= 5) { int bigstr = 0; if (rol2.Bigski.Str > 0) { bigstr = ran.Next(((rol2.Bigski.Str) / 10) * 8, ((rol2.Bigski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol2.Bigski.Name, rol1.Name, bigstr, rol1.Name, (rol1.Blood - bigstr)); rol1.Blood -= bigstr; } else { bigstr = ran.Next((Math.Abs(rol2.Bigski.Str) / 10) * 8, (Math.Abs(rol2.Bigski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆☆☆{1}☆☆☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol2.Name, rol2.Bigski.Name, bigstr, rol2.Name, (rol2.Blood + bigstr)); rol2.Blood += bigstr; } } else if (ran2 <= 20) { int smlstr = 0; if (rol2.Smlski.Str > 0) { smlstr = ran.Next(((rol2.Smlski.Str) / 10) * 8, ((rol2.Smlski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆{1}☆,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol2.Smlski.Name, rol1.Name, smlstr, rol1.Name, (rol1.Blood - smlstr)); rol1.Blood -= smlstr; } else { smlstr = ran.Next((Math.Abs(rol2.Smlski.Str) / 10) * 8, (Math.Abs(rol2.Smlski.Str) / 10) * 12); Console.WriteLine("【{0}】释放了☆{1}☆,治疗了自己{2}点血量,【{3}】剩余血量{4}", rol2.Name, rol2.Smlski.Name, smlstr, rol2.Name, (rol2.Blood + smlstr)); rol2.Blood += smlstr; } } else { int str = ran.Next(((rol2.Str) / 10) * 8, ((rol2.Str) / 10) * 12); Console.WriteLine("【{0}】攻击了【{1}】,对【{2}】造成了{3}点伤害,【{4}】剩余血量{5}", rol2.Name, rol1.Name, rol1.Name, str, rol1.Name, (rol1.Blood - str)); rol1.Blood -= str; } Console.WriteLine(); if (rol1.Blood <= 0) { Console.WriteLine("【{0}】阵亡,【{1}】获得了胜利。", rol1.Name, rol2.Name); break; } System.Threading.Thread.Sleep(1500); } Console.ReadKey(); } } }
练习——对战游戏
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。