首页 > 作文

C#实现简单的飞行棋小游戏

更新时间:2023-04-03 22:11:55 阅读: 评论:0

本文实例为大家分享了c#实现简单飞行棋小游戏的具体代码,供大家参考,具体内容如下

1.玩家姓名的输入

2.对屏幕进行清屏

3.初始化地图

4.玩家a和玩家b玩游戏

using system;namespace homework{class data{//静态字段来模拟全局变量static int[] maps = new int[100];//声明一个静态数组用来存储玩家a跟玩家b的坐标static int[] playerpos = new int[2];static string[] playernames = new string[2];//两个玩家的标记static bool[] flags = new bool[2];//flags[0]默认是fal public static void main(string[] args){gameshow();//玩家姓名的输入#region console.writeline("请输入玩家a的姓名:");playernames[0] = console.readline();while (playernames[浙江的市0] == ""){console.writeline("玩家a的姓名不能为空,请重新输入");playernames[0] = console.readline();}console.writeline("请输入玩家b的姓名:");playernames[1] = console.readline();while (playernames[1] == "" || playernames[1] == playernames[0]){if (playernames[0] == ""){console.writeline("玩家a的姓名不能为空,请重新输入");playernames[1] = console.readline();}el{console.writeline("玩家b的姓名不能与玩家a相同");playernames[1] = console.readline();}}#endregion//对屏幕进行清屏#region console.clear();//清屏gameshow();console.writeline(好心情美文网站"{0}的士兵用a表示", playernames[0]);console.writeline("{0}的士兵用b表示", playernames[1]);#endregion//画地图之前 初始化地图#region initailmap();drawmap();#endregion//当玩家a跟玩家b没有一个人在终点时候 两个玩家不停地去玩游戏#region while (playerpos[0] < 99 && playerpos[0] < 99){if (flags[0] == fal){playgame(0);}el{flags[0] = fal;}if (playerpos[0] > 99){console.writeline("玩家{0}赢了玩家{1}", playernames[0], playernames[1]);break;}if (flags[1] == fal){playgame(1);}el{flags[1] = fal;}if (playerpos[0] > 99){console.writeline("玩家{0}赢了玩家{1}", playernames[0], playernames[1]);break;}}//while#endregionconsole.writeline("游戏结束!!!");console.readline();}//画地图头#region public static void gameshow(){console.foregroundcolor = consolecolor.gray;console.writeline("*************************************");console.writeline("*************************************");console.writeline("****************飞行棋***************");console.writeline("*************************************");console.writeline("*************************************");}#endregion//初始化地图#region public static void initailmap(){int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘for (int i = 0; i < luckyturn.length; i++){maps[luckyturn[i]] = 1;}int[] landmine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷for (int i = 0; i < landmine.length; i++){maps[landmine[i]] = 2;}int[] pau = { 2,3,4,9, 27, 60, 93 };//暂停for (int i = 0; i < pau.length; i++){maps[pau[i]] = 3;}int[] timetunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道for (int i = 0; i < timetunnel.length; i++){maps[timetunnel[i]] = 4;}}#endregion//画地图#region public static void drawmap(){console.writeline("图例:幸运圆圈:○  地雷:  暂停:▽  时空隧道:◎");//第一横行for (int i = 0; i < 30; i++){//如果玩家a跟玩家b的坐标相同,画一个尖括号console.write(drawstringmap(i));}//forconsole.writeline();// 第一竖行for (int i = 30; i < 35; i++){for (int j = 0; j <= 28; j++){console.write("  ");}console.writeline(drawstringmap(i));}//第二横行for (int i = 64; i >= 35; i--){console.write(drawstringmap(i));}//画第二行 需要进行换行console.writeline();//第二竖行for (int i = 65; i <= 69; i++){console.writeline(drawstringmap(i));}//第三横行for (int i = 70; i <= 99; i++){console.write(drawstringma你不再需要我p(i));}console.writeline();}#endregion//画地图中抽象出一个方法#regionpublic static string drawstringmap(int i){string str = "";if (playerpos[0] == playerpos[1] && playerpos[1] == i){str = "<>";}el if (playerpos[0] == i){str = "a";}el if (playerpos[1] == i){str = "b";}el{switch (maps[i]){ca 0: str = "□"; break;ca 1: str = "○"; break;ca 2: str = ""; break;ca 3: str = "▽"; break;ca 4: str = "◎"; break;}//switch}//elreturn str;}#endregion//双方掷骰子过程#region public static void playgame(int playernumber){random r = new random();int rnumber = r.next(1, 7);console.writeline("{0}按人任意键开始掷骰子", playernames[playernumber]);console.readkey(true);console.writeline("{0}掷骰子掷出了{1}", playernames[playernumber], rnumber);playerpos[playernumber] += rnumber;console.readkey(true);console.writeline("{0}按任意键开始行动", playernames[playernumber]);console.readkey(true);console.writeline("{0}行动完了", playernames[playernumber]);console.readkey(true);//玩家a有可能踩到了玩家b 方块 幸运玩家 地雷 暂停 时空隧道if (playerpos[playernumber] == playerpos[1 - playernumber]){console.writeline("玩家{0}踩到了玩家{1},玩家{1}退6格", playernames[playernumber], playernames[1 - playernumber]);playerpos[1 - playernumber] -= 6;console.readkey(true);}el//踩到关卡{//玩家坐标switch (maps[playerpo无失其时s[playernumber]]){ca 0:console.writeline("玩家{0}踩到了方块,安全", playernames[playernumber]);console.readkey(true);break;ca 1:console.writeline("玩家{0}踩到幸运圆圈,请选择1--交换位置 2--轰炸对方", playernames[playernumber]);string input = console.readline();while (true){if (input == "1"){console.writeline("玩家{0}选择跟玩家{1}交换位置", playernames[playernumber], playernames[1 - playernumber]);console.readkey(true);int temp = playerpos[playernumber];playerpos[playernumber] = playerpos[1 - playernumber];playerpos[1 - playernumber] = temp;console.writeline("交换完成!!!按任意键继续游戏!!!");console.readkey(true);break;}el if (input == "2"){console.writeline("玩家{0}选择轰炸玩家{1},玩家{1}退6格", playernames[playernumber], playernames[1 - playernumber]);console.readkey(true);playerpos[1] -= 6;console.writeline("玩家{0}退了6格", playernames[1 - playernumber]);console.readkey(true);brea玉米何时传入中国k;}el{console.writeline("只能输入1或者2 1--交换位置  2--轰炸对方");input = console.readline();}}console.readkey(true);break;ca 2:console.writeline("玩家{0}踩到了地雷,退6格", playernames[playernumber]);console.readkey(true);playerpos[1 - playernumber] -= 6;console.writeline("玩家{0}退了6格", playernames[playernumber]);console.readkey(true);break;ca 3:console.writeline("玩家{0}踩到了暂停,暂停一回合", playernames[playernumber]);flags[playernumber] = true;console.readkey(true);break;ca 4:console.writeline("玩家{0}踩到了时空隧道,前进10格", playernames[playernumber]);console.readkey(true);playerpos[playernumber] += 10;break;}//switch}//elchangepos();console.clear();drawmap();}#endregion//当玩家坐标发生改变需要判断两者是否超出范围#region public static void changepos(){if (playerpos[0] < 0){playerpos[0] = 0;}if (playerpos[0] >= 99){playerpos[0] = 99;}if (playerpos[1] < 0){playerpos[1] = 0;}if (playerpos[1] > 99){playerpos[1] = 99;}}#endregion}}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-03 22:11:54,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/8771fbee0e64c15ba4dc305ae5d71156.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:C#实现简单的飞行棋小游戏.doc

本文 PDF 下载地址:C#实现简单的飞行棋小游戏.pdf

标签:玩家   踩到   姓名   地雷
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图