class 对战713 { struct Player { public string Name; public int Blood; public int Attact; public int Defence; public int DuoBi; public ArrayList JiNeng; public ArrayList ShangHai; } static void Main (string[] args) { #region 定义技能库 string[] JN; int[] SH; jineng(out JN, out SH); #endregion Console.WriteLine("请输入玩家1姓名:"); string name1 = Console.ReadLine(); Console.WriteLine("请输入玩家2姓名:"); string name2 = Console.ReadLine(); #region 造玩家,显示基本信息 //造玩家 Random sj = new Random(); //造玩家 Player P1 = wanjia(JN,SH,name1,sj); Player P2 = wanjia(JN,SH,name2,sj); #endregion //显示信息 jbxx(ref P1, ref P2); Console.WriteLine("按下回车键开始战斗"); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key.ToString().ToLower() == "enter") { while (true) { #region 胜负条件 if (P1.Blood == 0 && P2.Blood == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("{0}与{1}同归于尽了~!",P1.Name,P2.Name); break; } else if (P2.Blood == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("{0}把{1}KO了~!",P1.Name,P2.Name); break; } else if (P1.Blood == 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("{0}把{1}KO了~!", P2.Name, P1.Name); break; } #endregion //P1打P2 dajia(sj, ref P1, ref P2); //P2打P1 dajia(sj,ref P2,ref P1); // 显示剩余血量 xueliang(ref P1, ref P2); Console.WriteLine(); Thread.Sleep(2000); } } } private static void jbxx(ref Player P1, ref Player P2) { Console.WriteLine("姓名:{0}\t血量:{1}\t攻击力:{2}\t防御:{3}\t躲避:{4}\t所学技能:{5}、{6}、{7}", P1.Name, P1.Blood, P1.Attact, P1.Defence, P1.DuoBi, P1.JiNeng[0], P1.JiNeng[1], P1.JiNeng[2]); Console.WriteLine("姓名:{0}\t血量:{1}\t攻击力:{2}\t防御:{3}\t躲避:{4}\t所学技能:{5}、{6}、{7}", P2.Name, P2.Blood, P2.Attact, P2.Defence, P2.DuoBi, P2.JiNeng[0], P2.JiNeng[1], P2.JiNeng[2]); } private static void xueliang(ref Player P1, ref Player P2) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("{0}的剩余血量为:{1}\t{2}的剩余血量为:{3}", P1.Name, P1.Blood, P2.Name, P2.Blood); } private static void dajia(Random sj, ref Player P1, ref Player P2) { if (sj.Next(10) >= 8)//使用技能 { Console.ForegroundColor = ConsoleColor.White; int xx = sj.Next(3); Console.WriteLine("{0}使用了{1}技能,对{2}造成了{3}点伤害!", P1.Name, P1.JiNeng[xx], P2.Name, P1.ShangHai[xx]); P2.Blood -= Convert.ToInt32(P1.ShangHai[xx]); if (P2.Blood <= 0) { P2.Blood = 0; } } else //普通攻击 { //P2躲避攻击 if (P2.DuoBi >= sj.Next(11)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}躲避了{1}的攻击~!", P2.Name, P1.Name); } else//p2未躲避 { Console.ForegroundColor = ConsoleColor.Red; int ptsh1 = P1.Attact + sj.Next(50) - P2.Defence - sj.Next(30);//p1造成的伤害 Console.WriteLine("{0}对{1}进行攻击,造成{2}点伤害", P1.Name, P2.Name, ptsh1); P2.Blood -= ptsh1; if (P2.Blood <= 0) { P2.Blood = 0; } } } } private static Player wanjia(string[] JN, int[] SH, string name1, Random sj) { Player P1 = new Player(); int seed1; if (name1.Length == 2) { seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1)); } else { seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1)) + (int)Convert.ToChar(name1.Substring(2, 1)); } Random r1 = new Random(seed1); P1.Name = name1; P1.Blood = 2000 + r1.Next(1200); P1.Attact = 200 + r1.Next(50); P1.Defence = 100 + r1.Next(30); P1.DuoBi = 1 + r1.Next(3); P1.JiNeng = new ArrayList(); P1.ShangHai = new ArrayList(); for (int i = 0; i < 3; i++) { int x = sj.Next(10); if (!P1.JiNeng.Contains(JN[x])) { P1.JiNeng.Add(JN[x]); P1.ShangHai.Add(SH[x]); } else { i--; } } return P1; } private static void jineng(out string[] JN, out int[] SH) { JN = new string[] { "龙腾", "横扫千军", "后发制人", "双龙戏珠", "紧箍咒", "五雷轰顶", "猛击", "鹰击", "魅惑", "阎罗令" }; SH = new int[] { 400, 480, 350, 420, 290, 460, 330, 500, 380, 399 }; } } }
时间: 2024-10-12 15:36:08