标签:
class Program { struct player { public string name; public int hp; public int gj; public int fy; public int sf; //public wugong wg; } struct wugong //自定义武功类型 { public string name; public int gj; } static void Main(string[] args) { wugong [] wg =new wugong[3];//大招数组 定义大招 wg[0].name ="降龙十八掌"; wg[0].gj = 500; wg[1].name = "乾坤大挪移"; wg[1].gj = 600; wg[2].name = "一阳指"; wg[2].gj = 400; player p1 = new player(); //生成俩个人物 player p2 = new player(); Console.Write("请输入第一个人的名字:"); p1.name = Console.ReadLine(); Console.Write("请输入第二个人的名字:"); p2.name = Console.ReadLine(); Random r = new Random(); p1.hp = r.Next(500) + 2000; //生成血 p2.hp = r.Next(500) + 2000; p1.gj = r.Next(70) + 100; //生成攻击 p2.gj = r.Next(70) + 100; p1.fy = r.Next(50) + 100; //生成防御 p2.fy = r.Next(50) + 100; p1.sf = r.Next(20) ; //生成身法 p2.sf = r.Next(20) ; //输出随机的血量 攻击力 防御力 敏捷度 Console.WriteLine("姓名:" + p1.name + "\t血量值:" + p1.hp + "\t攻击力:" + p1.gj + "\t防御力:" + p1.fy + "\t敏捷度:" + p1.sf); Console.WriteLine("vs"); Console.WriteLine("姓名:" + p2.name + "\t血量值:" + p2.hp + "\t攻击力:" + p2.gj + "\t防御力:" + p2.fy + "\t敏捷度:" + p2.sf); Console.WriteLine("任意键开始"); Console.ReadKey(); //输出对战后的结果 while (true) { if (p1.hp <= 0 && p2.hp <= 0) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine("俩人都挂"); break; } if (p1.hp <= 0) { Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine(p2.name + "把" + p1.name + "KO了"); Console.ResetColor(); break; } if (p2.hp <= 0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(p1.name + "把" + p2.name + "KO了"); Console.ResetColor(); break; } //对战 System.Threading.Thread.Sleep(400); //p2大招 int dz1 = r.Next(10); if (dz1 >= 8) { wugong wg1 = wg[r.Next(3)]; int b1 = r.Next(100); int g1 = r.Next(100) - 50; int f1 = r.Next(100) - 50; b1 = (b1 + (p2.gj + g1 + wg1.gj) - (p1.fy + f1)) < 0 ? 0 : (b1 + (p2.gj + g1 + wg1.gj) - (p1.fy + f1));//血量可能成为负数 条件运算符 p1.hp -= b1; if (p1.hp < 0) { p1.hp = 0; } Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(p2.name + "使用大招" + wg1.name + "发起攻击" + p1.name + "掉血" + b1 + "点"); Console.ResetColor(); Console.WriteLine(); } //普通招式 else { int sf1 = r.Next(100); if (p1.sf - sf1 >= 0) { Console.WriteLine(p1.name + "躲过了" + p2.name + "攻击"); } else { int b1 = r.Next(100); int g1 = r.Next(100) - 50; int f1 = r.Next(100) - 50; b1 = (b1 + (p2.gj + g1) - (p1.fy + f1)) < 0 ? 0 : (b1 + (p2.gj + g1) - (p1.fy + f1));//血量可能成为负数 条件运算符 p1.hp -= b1; if (p1.hp < 0) { p1.hp = 0; } Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(p2.name + "发起攻击" + p1.name + "掉血" + b1 + "点"); Console.ResetColor(); Console.WriteLine(); } } System.Threading.Thread.Sleep(400); //随机生成p1大招 int dz2 = r.Next(10); if (dz2 >= 8) { wugong wg2 = wg[r.Next(3)]; int b2 = r.Next(100); int g2 = r.Next(100) - 50; int f2 = r.Next(100) - 50; b2 = (b2 + (p1.gj + g2 + wg2.gj) - (p2.fy + f2)) < 0 ? 0 : (b2 + (p1.gj + g2 + wg2.gj) - (p2.fy + f2));//血量可能成为负数 条件运算符 p2.hp -= b2; if (p2.hp < 0) { p2.hp = 0; } Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(p1.name + "使用大招" + wg2.name + "发起攻击" + p2.name + "掉血" + b2 + "点"); Console.ResetColor(); Console.WriteLine(); } //普通招式 else { int sf2 = r.Next(100); if (p2.sf - sf2 >= 0) { Console.WriteLine(p2.name + "躲过了" + p1.name + "攻击"); } else { int b2 = r.Next(100); int g2 = r.Next(100) - 50; int f2 = r.Next(100) - 50; b2 = (b2 + (p1.gj + g2) - (p2.fy + f2)) < 0 ? 0 : (b2 + (p1.gj + g2) - (p2.fy + f2));//血量可能成为负数 条件运算符 p2.hp -= b2; if (p2.hp < 0) { p2.hp = 0; } Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(p1.name + "发起攻击" + p2.name + "掉血" + b2 + "点"); Console.ResetColor(); Console.WriteLine(); } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("姓名" + p1.name + "血量值" + p1.hp+"\t"); Console.WriteLine("姓名" + p2.name + "血量值" + p2.hp); Console.ResetColor(); Console.WriteLine(); } Console.ReadLine(); } }
标签:
原文地址:http://www.cnblogs.com/Mr-xue/p/4429978.html