文章开始把我喜欢的这句话送个大家:这个世界上还有什么比自己写的代码运行在一亿人的电脑上更酷的事情吗,如果有那就是让这个数字再扩大十倍!!!
底部有下载链接:附带代码、答辩ppt、数据、音乐等素材。
1>创建一个hero类特征name(英雄名字),hp(血量),mp(魔法值), physicsattack(物理攻击力),magicattack(魔法攻击力)
2>创建一个battlecontrol战斗管理类,该类有两个字段分别为list<hero> ours(存储己方阵营中五个英雄)和list<hero> enemy(存储对方五个英雄)类型,分别创建五个英雄和五个敌人分别添加到对应list泛型列表中。添加int类型字段round 记录战斗开始到结束总的回合数。注:英雄名字自定义,血量200 魔法值100 攻击力自定义。
3>模拟回合制游戏逻辑,初始化完毕后首先己方攻击,每次攻击随机从对方阵营筛选一个敌人进行攻击,
每次造成的伤害为物理攻击和魔法攻击的叠加值,如果没有魔法值那么伤害值只是物理攻击力即可。
每次魔法攻击之后需要减去相应的魔法值,比如魔法攻击力为20,那么魔法值也需要消耗20个点。
攻击的同时输出信息格式:小一攻击了小二,小二剩余血量为80。
己方所有英雄攻击完毕之后,敌人攻击,攻击流程同上。
4>当某一个敌人或者己方英雄死亡后将死亡角色从对应list泛型列表中移除,某一个阵营全部死亡,游戏结束,开始结算,显示获胜方。显示总的回合数。
可思考完善上述流程,比如添加加血buff,技能释放,闪避等等功能,丰富战斗内容
ps:如有报错,请根据本机音乐文件设置绝对路径!!!
初始化界面:复制测试用例即可
开始界面
查看敌我方英雄信息界面
更改敌我方英雄状况界面
强化敌我方英雄属性界面
激活敌我方英雄大招界面
打斗界面
using system;using system.collections.generic;using system.threading;using system.linq;using system.text;using system.threading.tasks;using system.media;//在命名空间中添加namespace bigwork{class program{static void main(string[] args){system.media.soundplayer sp = new soundplayer();sp.soundlocation = @"e:\qianyan\大作业\test\music\英雄联盟 - welcome to planet urf.wav";sp.playlooping();list<hero> ours = new list<hero>(); //存放我方英雄集合list<hero> enemy = new list<hero>();//存放敌方英雄集合input(ours, enemy); //输入我方、敌方英雄信息(引用传递)battlecontrol.instance.ours = ours;battlecontrol.instance.enemy = enemy;while (true){function_print();string a = console.readline();if (string.isnullorempty(a)){console.writeline("输出指令有误,按任意键重新输入");console.readkey();console.clear();continue;}int n = int.par(a);switch (n){ca 1:showallinfo(ours);console.writeline("点击任意按键继续…………");console.readkey();console.clear();break;ca 2:showallinfo(enemy);console.writeline("点击任意按键继续…………");console.readkey();console.clear();break;ca 3:if (ours[0].modify == true)modifyinfo(ours);elconsole.writeline("战斗已经进行,无法再进行修改");console.readkey();console.clear();break;ca 4:if (ours[0].modify == true)modifyinfo(enemy);elconsole.writeline("战斗已经进行,无法再进行修改");console.readkey();console.clear();break;ca 5:strengthenhero(ours);break;ca 6:strengthenhero(enemy);break;ca 7:activateheroultimateskills(ours);break;ca 8:activateheroultimateskills(enemy);break;ca 9:system.media.soundplayer sp1 = new soundplayer();sp1.soundlocation = @"e:\qianyan\大作业\test\music\网络歌手 - 德玛德玛德玛西亚 00_00_00-00_00_04.wav";sp1.play();thread.sleep(5000);sp.soundlocation = @"e:\qianyan\大作业\test\music\英雄联盟 - welcome to planet urf.wav";sp.playlooping();battlecontrol.instance.fight(3);//3回合后激活一次break;}}console.readkey();}#region 输入我方、敌方英雄信息功能public static void input(list<hero> ours, list<hero> enemy){string a, d;int b, c;//输入我方英雄基本信息for (int i = 1; i <= 5; i++){console.writeline("请输入我方第{0}位英雄的名称:", i);a = console.readline();console.writeline("请输入我方第{0}位英雄的物理攻击力:", i);b = int.par(console.readline());console.writeline("请输入我方第{0}位英雄的魔法攻击力:", i);c = int.par(console.readline());console.writeline("请输入我方第{0}位英雄的终极技能:", i);d = console.readline();hero hero = new hero(a, b, c, d);ours.add(hero);console.clear(); //清屏函数}//输入敌方英雄基本信息for (int i = 1; i <= 5; i++){console.writeline("请输入敌方第{0}位英雄的名称:", i);a = console.readline();console.writeline("请输入敌方第{0}位英雄的物理攻击力:", i);b = int.par(console.readline());console.writeline("请输入敌方第{0}位英雄的魔法攻击力:", i);c = int.par(console.readline());console.writeline("请输入敌方第{0}位英雄的终极技能:", i);d = console.readline();hero hero = new hero(a, b, c, d);enemy.add(hero);console.clear(); //清屏函数}console.writeline("正在为您初始化英雄角色,请稍等…………");thread.sleep(1000);console.clear();}#endregion#region 显示功能选项函数//static:不用创建对象就可以调用public static void function_print(){console.writeline("****************************");console.writeline("* *");console.writeline("* 英雄大乱斗回合制游戏 *");console.writeline("* *");console.writeline("* 1、查看我方英雄情况 *");console.writeline("* 2、查看敌方英雄情况 *");console.writeline("* 3、更改我方英雄情况 *");console.writeline("* 4、更改敌方英雄情况 *");console.writeline("* 5、强化我方英雄 *");console.writeline("* 6、强化敌方英雄 *");console.writeline("* 7、激活我方英雄大招 *");console.writeline("* 8、激活敌方英雄大招 *");console.writeline("* 9、开始回合制打斗 *");console.writeline("* *");console.writeline("****************************");}#endregion#region 查看英雄信息函数public static void showallinfo(list<hero> hero){console.writeline("5位英雄信息如下:");foreach (var i in hero){i.showinfo();}}#endregion#region 修改信息public static void modifyinfo(list<hero> heros){string a;showallinfo(heros);console.write("\n输入修改的编号(从1开始):");a = console.readline();if (string.isnullorempty(a)){console.writeline("输入有误,重新选择");console.readline();console.clear();return;}int t = int.par(a);if (t > heros.count){console.writeline("输入数值超过英雄编号长度,重新选择需求");}el{hero hero = heros[t - 1];console.writeline("输入修改的值(按:姓名、血量、蓝量、物理攻击、魔法攻击写,不修改填-1或直接回车,填写好后按回车键修改各个值):");hero.tcolor(consolecolor.red, consolecolor.black);console.writeline("注:英雄终极技能一旦创建无法更改");hero.colorret();a = console.readline();if (a != "-1" && !string.isnullorempty(a))hero.name = a;a = console.readline();if (a != "-1" && !string.isnullorempty(a))hero.hp = int.par(a);a = console.readline();if (a != "-1" && !string.isnullorempty(a))hero.mp = int.par(a);a = console.readline();if (a != "-1" && !string.isnullorempty(a))hero.physicsattack = int.par(a);a = console.readline();if (a != "-1" && !string.isnullorempty(a))hero.magicattack = int.par(a);console.writeline("修改后的数据");showallinfo(heros);}}#endregion#region 强化英雄public static void strengthenhero(list<hero> heros){string a;showallinfo(heros);console.write("\n输入强化的编号(从1开始):");a = console.readline();if (string.isnullorempty(a)){console.writeline("输入有误,重新选择");console.readline();console.clear();return;}int t = int.par(a);if (t > heros.count){console.writeline("输入数值超过英雄编号长度,重新选择需求");console.readline();console.clear();}el{hero hero = heros[t - 1];console.write("添加血量值:");a = console.readline();if (!string.isnullorempty(a) && int.par(a) >= 0)hero.hp += int.par(a);console.write("添加蓝量值:");a = console.readline();if (!string.isnullorempty(a) && int.par(a) >= 0)hero.mp += int.par(a);console.write("设置红buff(输入1为设置):");a = console.readline();if (!string.isnullorempty(a) && int.par(a) == 1)hero.redbuff = true;console.write("设置蓝buff(输入1为设置):");a = console.readline();if (!string.isnullorempty(a) && int.par(a) == 1)hero.bluebuff = true;console.write("设置眩晕buff(输入1为设置):");a = console.readline();if (!string.isnullorempty(a) && int.par(a) == 1)hero.dizzybuff = true;}}#endregion#region 激活终极技能public static void activateheroultimateskills(list<hero> heros){console.writeline("终极技能激活情况");foreach (var hero in heros){console.write("{0}的终极技能:", hero.name);if (hero.activateultimateskills == fal){hero.tcolor(consolecolor.red, consolecolor.black);console.writeline("未激活");hero.colorret();}el{hero.tcolor(consolecolor.green, consolecolor.black);console.writeline("已激活");hero.colorret();}}console.write("\n输入激活大招的编号(从1开始):");string a = console.readline();if (string.isnullorempty(a)){console.writeline("输入有误,重新选择");console.readline();console.clear();return;}int t = int.par(a);if (t > heros.count){console.writeline("输入数值超过英雄编号长度,重新选择需求");console.readkey();}elheros[t - 1].activateultimateskills = true;console.clear();}#endregion}class hero{private string name;private int hp = 200; // 血量 private int mp = 100; // 魔法值private int physicsattack; // 物理攻击力private int magicattack; // 魔法攻击力private string ultimateskills; // 终极技能private bool sign = fal; //本回合攻击过就标记private bool modify = true; // 设置是否能再次修改信息private bool activateultimateskills = fal; // 终极技能的激活情况private bool bluebuff = fal; // 设置蓝buff效果private bool redbuff = fal; // 设置红buff效果 private bool dizzybuff = fal; // 设置晕眩buff效果private bool dizzy = fal; // 设置晕眩效果public string name { get => name; t => name = value; }public int hp { get => hp; t => hp = value; }public int mp { get => mp; t => mp = value; }public int physicsattack { get => physicsattack; t => physicsattack = value; }public int magicattack { get => magicattack; t => magicattack = value; }public string ultimateskills { get => ultimateskills; t => ultimateskills = value; }public bool modify { get => modify; t => modify = value; }public bool 新年祝语activateultimateskills { get => activateultimateskills; t => activateultimateskills = value; }public bool bluebuff { get => bluebuff; t => bluebuff = value; }public bool redbuff { get => redbuff; t => redbuff = value; }public bool dizzybuff { get => dizzybuff; t => dizzybuff = value; }public bool dizzy { get => dizzy; t => dizzy = value; }public bool sign { get => sign; t => sign = value; }public hero() { }public hero(string name, int physicsattack, int magicattack, string ultimateskills){this.name = name;this.physicsattack = physicsattack;this.magicattack = magicattack;this.ultimateskills = ultimateskills;}// 展示信息public void showinfo(){console.write("英雄名称:");tcolor(consolecolor.green, consolecolor.black);console.write(" " + name + " ");colorret();console.write(" 血量:");tcolor(consolecolor.red, consolecolor.black);console.write(" " + hp + " ");colorr英语怎样才能学好et();console.write(" 魔法值:");tcolor(consolecolor.blue, consolecolor.black);console.write(" " + mp + " ");colorret();console.write(" 物理攻击力:");tcolor(consolecolor.green, consolecolor.black);自动化排名console.write(" " + physicsattack + " ");colorret();console.write(" 魔法攻击力:");tcolor(consolecolor.green, consolecolor.black);console.write(" " + magicattack + " ");colorret();console.write(" 终极技能:");tcolor(consolecolor.cyan, consolecolor.black);console.write(" " + ultimateskills + " ");colorret();console.writeline();}public static void tcolor(consolecolor a, consolecolor b){console.backgroundcolor = a;console.foregroundcolor = b;}public static void colorret(){console.backgroundcolor = consolecolor.black;console.foregroundcolor = consolecolor.white;}}class battlecontrol{//回合private int round = 1;//己方人物private list<hero> ours;//敌方人物private list<hero> enemy;private static battlecontrol instance = null;private battlecontrol() { }public static battlecontrol instance{get{if (instance == null){instance = new battlecontrol();}return instance;}}public int round { get => round; t => round = value; }internal list<hero> ours { get => ours; t => ours = value; }internal list<hero> enemy { get => enemy; t => enemy = value; }//实现回合制打斗方法public void fight(int activation){int i, j;random random = new random();int sum = 0;while (true){console.writeline("第{0}回合开始!!!!!!!!", round);sum = 0;while (sum != (ours.count + enemy.count)){sum = 0;#region 选出所要战斗的英雄i = (int)random.next(0, ours.count);//我方英雄thread.sleep(1000);j = (int)random.next(0, enemy.count);//敌方英雄#endregion#region 大招//回合数达到三 就可以释放或者不释放if (round == activation){console.writeline("是否放大招1是放 2不放:");string a = console.readline();int n = int.par(a);for (int t = 0; t < ours.count; t++){if (ours[t].hp != 0){ours[t].activateultimateskills = true;}switch (n){ca 1:for (int k = 0; k < ours.count; k++){if (enemy[j].hp > 0){enemy[j].hp = enemy[j].hp > 10 ? enemy[j].hp - 10 : 0;}}break;ca 2:break;}}n = int.par(a);for (int t = 0; t < enemy.count; t++){if (enemy[t].hp != 0){ours[t].activateultimateskills = true;}switch (n){ca 1:for (int k = 0; k < ours.count; k++){if (ours[i].hp > 0){ours[i].hp = ours[i].hp > 10 ? ours[i].hp - 10 : 0;}}break;ca 2:break;}}}#endregionif (ours.count == 0){break;}if (enemy.count == 0){break;}if (!ours[i].sign && !enemy[j].sign)//本回合都未进攻过{//进攻操作 //首先把选出的英雄进行标记ours[i].sign = true;enemy[j].sign = true;//去判断双方所带的增益有哪些//如果进攻方有一方有眩晕buff就让对方眩晕if (ours[i].dizzybuff){enemy[j].dizzy = true;}if (enemy[j].dizzybuff){ours[i].dizzy = true;}//进攻的时候判断 如果已经被眩晕就不进攻if (ours[i].dizzy && !enemy[j].dizzy){enemy_attack(i, j);}el if (!ours[i].dizzy && enemy[j].dizzy){ours_attack(i, j);}el if (!ours[i].dizzy && !enemy[j].dizzy){ours_attack(i, j);enemy_attack(i, j);}el if (ours[i].dizzy && enemy[j].dizzy){console.writeline("双方都被眩晕所以这回合两个英雄都未掉血!!!");}}el if (ours[i].sign && !enemy[j].sign){enemy[j].sign = true;//把没有进行进攻的标记enemy_attack(i, j);}el if (!ours[i].sign && enemy[j].sign){ours[i].sign = true;//把没有进行进攻的标记ours_attack(i, j);}el if (ours[i].sign && enemy[j].sign){console.writeline("选出的两个英雄本回合都出战过~~~系统从新选择");}for (int k = 0; k < ours.count; k++){if (ours[k].sign == true){sum++;}}for (int k = 0; k < enemy.count; k++){if (enemy[k].sign == true){sum++;}}console.writeline("{0}与{1}对战,{2}剩余血量{3},{4}剩余血量{5}", ours[i].name, enemy[j].name, ours[i].name, ours[i].hp, enemy[j].name, enemy[j].hp);#region 如果已经战死就移除if (ours[i].hp == 0){console.writeline("{0}死亡将会从新选择英雄", ours[i].name);ours.remove(ours[i]);}if (enemy[j].hp == 0){console.writeline("{0}死亡将会从新选择英雄", enemy[j].name);enemy.remove(enemy[j]);}#endregion}console.writeline("第{0}回合结束!!!!!!!!", round);//一回合结束后更新所有英雄的状态update_status();if (ours.count == 0){break;}if (enemy.count == 0){break;}//更新回合数round++;}if (ours.count == 0){console.writeline("我方输");}el if (enemy.count == 0){console.writeline("敌方输");}el if (enemy.count == 0 && ours.count == 0){console.writeline("平局");}}//更新状态public void update_status(){int i;for (i = 0; i < ours.count; i++){ours[i].dizzy = fal;ours[i].sign = fal;//开局给的buff最多支撑三回合if (round == 3){ours[i].bluebuff = fal;ours[i].redbuff = fal;}}for (i = 0; i < enemy.count; i++){enemy[i].dizzy = fal;enemy[i].sign = fal;//开局给的buff最多支撑三回合if (round == 3){enemy[i].bluebuff = fal;enemy[i].redbuff = fal;}}}//ours进攻public void ours_attack(int i, int j){//红buffif (ours[i].redbuff){console.writeline("红buff对{0}造成10点伤害", enemy[j].name);//红buff造成的伤害,和回血//防止血量出现负数enemy[j].hp = enemy[j].hp > 10 ? enemy[j].hp - 10 : 0;if (ours[i].hp == 200){console.writeline("{0}血量已满无法回血", ours[i].name);}el{//防止血量超过200ours[i].hp = 200 > (ours[i].hp + 4) ? ours[i].hp + 4 : 200;console.writeline("{0}回了4点血", ours[i].name);}}//蓝buffif (ours[i].bluebuff){console.writeline("{0}回复了10点魔法值", ours[i].name);//最高值限定ours[i].mp = ours[i].mp + 10 > 100 ? 100 : ours[i].mp + 10;}//魔法攻击力加物理攻击力造成伤害-最高值限走进鲁迅定if (ours[i].mp >= ours[i].magicattack){enemy[j].hp = (ours[i].physicsattack + ours[i].magicattack) > enemy[j].hp ? 0 : enemy[j].hp - (ours[i].physicsattack + ours[i].magicattack);ours[i].mp -= ours[i].magicattack; //更新魔法值}el//魔法值不足以发动魔法攻击{enemy[j].hp = ours[i].physicsattack > enemy[j].hp ? 0 : enemy[j].hp - ours[i].physicsattack;}}//enemy进攻public void enemy_attack(int i, int j){//红buffif (enemy[j].redbuff){console.writeline("红buff对{0}造成10点伤害", ours[i].name);//红buff造成的伤害//防止血量出现负数ours[i].hp = ours[i].hp > 10 ? ours[i].hp - 10 : 0;if (enemy[j].hp == 200){console.writeline("{0}血量已满无法回血", enemy[j].name);}el{//防止血量超过200enemy[j].hp = 200 < (enemy[j].hp + 4) ? enemy[j].hp + 4 : 200;console.writeline("{0}回了4点血", enemy[j].name);}}//蓝buffif (enemy[j].bluebuff){console.writeline("{0}回复了10点魔法值", enemy[j].name);//最高值限定enemy[j].mp = enemy[j].mp + 10 > 100 ? 100 关于太炎先生二三事: enemy[j].mp + 10;}//魔法攻击力加物理攻击力造成伤害-最高值限定if (enemy[j].mp >= enemy[j].magicattack){ours[i].hp = (enemy[j].physicsattack + enemy[j].magicattack) > ours[i].hp ? 0 : ours[i].hp - (enemy[j].physicsattack + enemy[j].magicattack);enemy[j].mp -= enemy[j].magicattack; //更新魔法值}el//魔法值不足以发动魔法攻击{ours[i].hp = enemy[j].physicsattack > ours[i].hp ? 0 : ours[i].hp - enemy[j].physicsattack;}}}}
下载地址提取码:ycq9
以上就是基于c#模拟实现回合制游戏的详细内容,更多关于c#模拟回合制游戏的资料请关注www.887551.com其它相关文章!
本文发布于:2023-04-04 12:53:49,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/7a506727ea5021d7f46bb8d63c88ed9a.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:基于C#模拟实现回合制游戏.doc
本文 PDF 下载地址:基于C#模拟实现回合制游戏.pdf
留言与评论(共有 0 条评论) |