首页 > 代码库 > 对战游戏1.0
对战游戏1.0
//主函数
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { class Program { static void Main(string[] args) { Random r = new Random(); //战士,名字,生命值,攻击力,招式,闪躲 Soldier S1 = new Soldier(); Console.Write("请输入第一个战士的名字:"); S1.Name = Console.ReadLine(); S1.Blood = r.Next(2000,3001); int s1startblood = S1.Blood; S1.Attack = r.Next(50,101); Movements SM1 = new Movements(); Console.Write("请输入小招的名字:"); SM1.Name = Console.ReadLine(); SM1.Attack = r.Next(200,301); S1.Smallmove = SM1; Movements BM1 = new Movements(); Console.Write("请输入大招的名字:"); BM1.Name = Console.ReadLine(); BM1.Attack = r.Next(300, 401); S1.Smallmove = BM1; S1.Dodge = r.Next(0,50); S1.Restor = r.Next(100,301); Soldier S2 = new Soldier(); Console.Write("请输入第二个战士的名字:"); S2.Name = Console.ReadLine(); S2.Blood = r.Next(2000, 3001); int s2startblood = S2.Blood; S2.Attack = r.Next(50, 101); Movements SM2 = new Movements(); Console.Write("请输入小招的名字:"); SM2.Name = Console.ReadLine(); SM2.Attack = r.Next(200, 301); S2.Smallmove = SM2; Movements BM2= new Movements(); Console.Write("请输入大招的名字:"); BM2.Name = Console.ReadLine(); BM2.Attack = r.Next(300, 401); S2.Smallmove = BM2; S2.Dodge = r.Next(0, 50); S2.Restor = r.Next(100, 301); Console.Clear(); Console.WriteLine("=======================战士信息展示======================="); Console.WriteLine("名字\t生命值\t攻击力\t小招\t\t小招攻击力\t大招\t\t大招攻击力\t闪躲\t恢复值"); Console.WriteLine(S1.Name + "\t" + S1.Blood + "\t" + S1.Attack + "\t" + SM1.Name + "\t\t" + SM1.Attack + "\t" + BM1.Name + "\t\t" + BM1.Attack + "\t" + S1.Dodge + "\t" + S1.Restor); Console.WriteLine(S2.Name + "\t" + S2.Blood + "\t" + S2.Attack + "\t" + SM2.Name + "\t\t" + SM2.Attack + "\t" + BM2.Name + "\t\t" + BM2.Attack + "\t" + S2.Dodge + "\t" + S2.Restor); Console.ReadKey(); //开始战斗,不死不休 int whostart = r.Next(1,3); //战士一先开始攻击 if (whostart == 1) { int count = 1; while (true) { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("=======================第"+count+"回合======================="); //战士一开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 if (r.Next(0, 101) < S1.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S2.Name + "躲掉了" + S1.Name + "的攻击!"); } else { //发大招 if(r.Next(1,101)>95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了卐卐卐卐卐" + BM1.Name + "卐卐卐卐卐,攻击力为" + BM1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - BM1.Attack) + "!"); S2.Blood -= BM1.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了卐卐" + SM1.Name + "卐卐,攻击力为" + SM1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - SM1.Attack) + "!"); S2.Blood -= SM1.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了普通攻击,攻击力为" + S1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - S1.Attack) + "!"); S2.Blood -= S1.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if(S2.Blood<=0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S1.Name + "获胜," + S2.Name + "阵亡!"); break; } } //战士二开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 Console.ForegroundColor = ConsoleColor.Black; if (r.Next(0, 101) < S2.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S1.Name + "躲掉了" + S2.Name + "的攻击!"); } else { //发大招 if(r.Next(1,101)>95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S2.Name + "对" + S1.Name + "发出了卐卐卐卐卐" + BM2.Name + "卐卐卐卐卐,攻击力为" + BM2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - BM2.Attack) + "!"); S1.Blood -= BM2.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S2.Name + "对" + S2.Name + "发出了卐卐" + SM2.Name + "卐卐,攻击力为" + SM2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - SM2.Attack) + "!"); S1.Blood -= SM2.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S2.Name + "对" + S1.Name + "发出了普通攻击,攻击力为" + S2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - S2.Attack) + "!"); S1.Blood -= S2.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if(S1.Blood<=0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S2.Name + "获胜," + S1.Name + "阵亡!"); break; } } if (S1.Blood > 0 && S2.Blood > 0) { if (r.Next(1, 11) == 1) { S1.Blood += S1.Restor; if (S1.Blood > s1startblood) { S1.Blood = s1startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S1.Name + "拣到仙豆,生命值恢复到:" + S1.Blood); } if (r.Next(1, 11) == 2) { S2.Blood += S2.Restor; if (S2.Blood > s2startblood) { S2.Blood = s2startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S2.Name + "拣到仙豆,生命值恢复到:" + S2.Blood); } } count++; } } //战士二先开始攻击 else { int count = 1; while (true) { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("=======================第"+count+"回合======================="); //战士二开始攻击 System.Threading.Thread.Sleep(2000); //闪躲 if (r.Next(0, 101) < S2.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S1.Name + "躲掉了" + S2.Name + "的攻击!"); } else { //发大招 if (r.Next(1, 101) > 95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S2.Name + "对" + S1.Name + "发出了卐卐卐卐卐" + BM2.Name + "卐卐卐卐卐,攻击力为" + BM2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - BM2.Attack) + "!"); S1.Blood -= BM2.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S2.Name + "对" + S2.Name + "发出了卐卐" + SM2.Name + "卐卐,攻击力为" + SM2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - SM2.Attack) + "!"); S1.Blood -= SM2.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S2.Name + "对" + S1.Name + "发出了普通攻击,攻击力为" + S2.Attack + "," + S1.Name + "剩余生命值" + (S1.Blood - S2.Attack) + "!"); S1.Blood -= S2.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if (S1.Blood <= 0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S2.Name + "获胜," + S1.Name + "阵亡!"); break; } } //战士一开始攻击 System.Threading.Thread.Sleep(2000); Console.ForegroundColor = ConsoleColor.Black; //闪躲 if (r.Next(0, 101) < S1.Dodge) { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine(S2.Name + "躲掉了" + S1.Name + "的攻击!"); } else { //发大招 if (r.Next(1, 101) > 95) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了卐卐卐卐卐" + BM1.Name + "卐卐卐卐卐,攻击力为" + BM1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - BM1.Attack) + "!"); S2.Blood -= BM1.Attack; Console.WriteLine(); } //发小招 else if (r.Next(1, 101) >= 80 && r.Next(1, 101) <= 95) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了卐卐" + SM1.Name + "卐卐,攻击力为" + SM1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - SM1.Attack) + "!"); S2.Blood -= SM1.Attack; Console.WriteLine(); } //普通攻击 else { Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine(S1.Name + "对" + S2.Name + "发出了普通攻击,攻击力为" + S1.Attack + "," + S2.Name + "剩余生命值" + (S2.Blood - S1.Attack) + "!"); S2.Blood -= S1.Attack; Console.WriteLine(); } //判断战士二是否阵亡 if (S2.Blood <= 0) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine(S1.Name + "获胜," + S2.Name + "阵亡!"); break; } } if(S1.Blood>0&&S2.Blood>0) { if(r.Next(1,11)==1) { S1.Blood += S1.Restor; if(S1.Blood>s1startblood) { S1.Blood = s1startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S1.Name+"拣到仙豆,生命值恢复到:"+S1.Blood); } if (r.Next(1, 11) == 2) { S2.Blood += S2.Restor; if (S2.Blood > s2startblood) { S2.Blood = s2startblood; } Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(S2.Name + "拣到仙豆,生命值恢复到:" + S2.Blood); } } count++; } } Console.ReadKey(); } } }
//Soldier类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { public class Soldier { //名字,生命值,攻击力,招式,闪躲,恢复 private string _name; /// <summary> /// 战士姓名 /// </summary> public string Name { get { return _name; } set { _name = value; } } private int _blood; /// <summary> /// 战士生命值 /// </summary> public int Blood { get { return _blood; } set { _blood = value; } } private int _attack; /// <summary> /// 战士攻击力 /// </summary> public int Attack { get { return _attack; } set { _attack = value; } } private Movements _smallmove; /// <summary> /// 战士招式:小招 /// </summary> public Movements Smallmove { get { return _smallmove; } set { _smallmove = value; } } private Movements _bigmove; /// <summary> /// 战士招式:大招 /// </summary> public Movements Bigmove { get { return _bigmove; } set { _bigmove = value; } } private int _dodge; /// <summary> /// 战士闪躲攻击值 /// </summary> public int Dodge { get { return _dodge; } set { _dodge = value; } } private int _restor; /// <summary> /// 战士生命恢复值 /// </summary> public int Restor { get { return _restor; } set { _restor = value; } } } }
//Moverments类 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 作业_对战游戏 { public class Soldier { //名字,生命值,攻击力,招式,闪躲,恢复 private string _name; /// <summary> /// 战士姓名 /// </summary> public string Name { get { return _name; } set { _name = value; } } private int _blood; /// <summary> /// 战士生命值 /// </summary> public int Blood { get { return _blood; } set { _blood = value; } } private int _attack; /// <summary> /// 战士攻击力 /// </summary> public int Attack { get { return _attack; } set { _attack = value; } } private Movements _smallmove; /// <summary> /// 战士招式:小招 /// </summary> public Movements Smallmove { get { return _smallmove; } set { _smallmove = value; } } private Movements _bigmove; /// <summary> /// 战士招式:大招 /// </summary> public Movements Bigmove { get { return _bigmove; } set { _bigmove = value; } } private int _dodge; /// <summary> /// 战士闪躲攻击值 /// </summary> public int Dodge { get { return _dodge; } set { _dodge = value; } } private int _restor; /// <summary> /// 战士生命恢复值 /// </summary> public int Restor { get { return _restor; } set { _restor = value; } } } }
对战游戏1.0
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。