C#控制台实现简单飞行棋游戏_第1页
C#控制台实现简单飞行棋游戏_第2页
C#控制台实现简单飞行棋游戏_第3页
C#控制台实现简单飞行棋游戏_第4页
C#控制台实现简单飞行棋游戏_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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

需求分析

1.制作游戏头部:游戏头部介绍

2.绘制地图

使用一维数组装整个地图的路线

如果这个位置是0,绘制普通格子□

如果这个位置是1,绘制幸运轮盘◎

如果这个位置是2,绘制地雷★

如果这个位置是3,绘制暂停▲

如果这个位置是4,绘制时空隧道卍

规划幸运轮盘位置

int[]luckyturn={6,23,40,55,69,83};

规划地雷的位置

int[]landMine={5,13,17,33,38,50,64,80,94};

规划暂停位置

int[]pause={9,27,60,93};

规划时空隧道的位置

int[]timeTunnel={20,25,45,63,72,88,90};

3.设置特殊关卡

代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Threading.Tasks;

namespace_01飞行棋

classProgram

///summary

///整个地图数组

////summary

staticint[]Maps=newint[100];

///summary

///存储玩家的数组

////summary

staticint[]PlayerPos=newint[2];

///summary

///玩家名称的数组

////summary

staticstring[]PlayerName=newstring[2];

staticbool[]PlayerFlage=newbool[2];

staticvoidMain(string[]args)

//绘制游戏标题

ShowTitle();

//输入玩家名称

Console.WriteLine("请输入玩家A的姓名:");

PlayerName[0]=Console.ReadLine();

while(PlayerName[0]=="")

Console.WriteLine("玩家A的姓名不能为空,请重新输入!");

PlayerName[0]=Console.ReadLine();

Console.WriteLine("请输入玩家B的姓名:");

PlayerName[1]=Console.ReadLine();

while(PlayerName[1]==""||PlayerName[1]==PlayerName[0])

if(PlayerName[1]=="")

Console.WriteLine("玩家B的姓名不能为空,请重新输入!");

PlayerName[1]=Console.ReadLine();

if(PlayerName[1]==PlayerName[0])

Console.WriteLine("玩家B的姓名和A重复,请重新输入!");

PlayerName[1]=Console.ReadLine();

//输入完姓名,清空屏幕

Console.Clear();

ShowTitle();

//初始化地图关卡

InitialMap();

//绘制地图

DrawMap();

Console.ReadLine();

while(PlayerPos[0]99PlayerPos[1]99)

if(PlayerFlage[0]==false)

PlayGame(0);

else

PlayerFlage[0]=false;

if(PlayerFlage[1]==false)

PlayGame(1);

else

PlayerFlage[1]=false;

if(PlayerPos[0]==99)

Console.WriteLine("恭喜玩家[{0}]获胜",PlayerName[0]);

if(PlayerPos[1]==99)

Console.WriteLine("恭喜玩家[{0}]获胜",PlayerName[1]);

///summary

///设置游戏标题

////summary

staticvoidShowTitle()

//设置颜色

Console.ForegroundColor=ConsoleColor.Cyan;

Console.WriteLine("************************************");

Console.ForegroundColor=ConsoleColor.Green;

Console.WriteLine("************************************");

Console.ForegroundColor=ConsoleColor.Blue;

Console.WriteLine("************************************");

Console.ForegroundColor=ConsoleColor.Yellow;

Console.WriteLine("***************飞行棋***************");

Console.ForegroundColor=ConsoleColor.Blue;

Console.WriteLine("************************************");

Console.ForegroundColor=ConsoleColor.Green;

Console.WriteLine("************************************");

Console.ForegroundColor=ConsoleColor.Cyan;

Console.WriteLine("************************************");

///summary

///初始化地图关卡

////summary

staticvoidInitialMap()

//确定幸运轮盘的位置◎==1

int[]luckyturn={6,23,40,55,69,83};

for(inti=0;iluckyturn.Length;i++)

Maps[luckyturn[i]]=1;

//确定地雷的位置★==2

int[]landMine={5,13,17,33,38,50,64,80,94};

for(inti=0;ilandMine.Length;i++)

Maps[landMine[i]]=2;

//确定暂停的位置▲==3

int[]pause={9,27,60,93};

for(inti=0;ipause.Length;i++)

Maps[pause[i]]=3;

//确定时空隧道的位置卍==4

int[]timeTunnel={20,25,45,63,72,88,90};

for(inti=0;itimeTunnel.Length;i++)

Maps[timeTunnel[i]]=4;

///summary

///绘制地图

////summary

staticvoidDrawMap()

Console.ForegroundColor=ConsoleColor.Blue;

Console.WriteLine("玩家[{0}]使用A表示",PlayerName[0]);

Console.WriteLine("玩家[{0}]使用B表示",PlayerName[1]);

Console.WriteLine("游戏规则:");

Console.WriteLine("1.两名玩家轮流掷骰子,规定A玩家先掷.");

Console.WriteLine("2.踩到□格子安全,没有奖惩!");

Console.WriteLine("3.踩到◎幸运轮盘,可以进行两种选择:a.置换与对方玩家的位置;b.进行轰炸对方,使对方倒退6步");

Console.WriteLine("4.踩到★地雷,倒退6步!");

Console.WriteLine("5.踩到▲暂停,下个回合将暂停操作!");

Console.WriteLine("6.踩到卍时空隧道,直接前进10步!");

Console.WriteLine("7.如果踩到对方,则对方直接退6步!");

///第一横行

for(inti=0;ii++)

//判断两个玩家的位置一样,确定两个玩家还都在地图中

Console.Write(DrawString(i));

Console.WriteLine();

///第一竖列

for(inti=30;ii++)

for(intj=0;jj++)

Console.Write("");

Console.WriteLine(DrawString(i));

///第二横行

for(inti=64;ii--)

Console.Write(DrawString(i));

Console.WriteLine();

///第二竖列

for(inti=65;ii++)

Console.WriteLine(DrawString(i));

///第三横行

for(inti=70;ii++)

Console.Write(DrawString(i));

Console.WriteLine();

///summary

///判断绘制地图的方法

////summary

///paramname="pos"/param

privatestaticstringDrawString(intpos)

stringstr="";

if(PlayerPos[0]==PlayerPos[1]PlayerPos[0]==pos)

Console.ForegroundColor=ConsoleColor.DarkRed;

str="";

elseif(PlayerPos[0]==pos)

Console.ForegroundColor=ConsoleColor.Magenta;

str="A";

elseif(PlayerPos[1]==pos)

Console.ForegroundColor=ConsoleColor.DarkBlue;

str="B";

else

switch(Maps[pos])

case0:

Console.ForegroundColor=ConsoleColor.Cyan;

str="□";

break;

case1:

Console.ForegroundColor=ConsoleColor.Green;

str="◎";

break;

case2:

Console.ForegroundColor=ConsoleColor.Red;

str="★";

break;

case3:

Console.ForegroundColor=ConsoleColor.Blue;

str="▲";

break;

case4:

Console.ForegroundColor=ConsoleColor.Yellow;

str="卍";

break;

default:

break;

returnstr;

//游戏环节

staticvoidPlayGame(intplayerNum)

Randomr=newRandom();

Console.WriteLine("玩家[{0}]按下任意键掷骰子.",PlayerName[playerNum]);

Console.ReadKey(true);

intnumber=r.Next(1,7);

Console.WriteLine("玩家[{0}]掷出{1}点.",PlayerName[playerNum],number);

Console.WriteLine("玩家[{0}]按下任意键进行移动.",PlayerName[playerNum]);

Console.ReadKey(true);

PlayerPos[playerNum]+=number;

Console.WriteLine("玩家[{0}]移动完成!",PlayerName[playerNum]);

//玩家踩到对方

ChangedCheck();

if(PlayerPos[playerNum]==PlayerPos[1-playerNum])

Console.WriteLine("玩家[{0}]踩到玩家[{1}],玩家[{1}]退6步",PlayerName[playerNum],PlayerName[1-playerNum]);

PlayerPos[1-playerNum]-=6;

else

switch(Maps[PlayerPos[playerNum]])

//踩到普通地板,安全没有奖惩

case0:

Console.WriteLine("玩家[{0}]踩到安全地带,没有奖惩!按下任意键继续游戏",PlayerName[playerNum]);

Console.ReadKey(true);

break;

//踩到1幸运轮盘,选择奖励

case1:

Console.WriteLine("玩家[{0}]踩到幸运轮盘,请选择:a--交换位置b--轰炸对方.",PlayerName[playerNum]);

stringinput=Console.ReadLine();

while(true)

if(input=="a")

Console.WriteLine("玩家[{0}]选择与玩家[{1}]交换位置.",PlayerName[playerNum],PlayerName[1-playerNum]);

inttemp=PlayerPos[playerNum];

PlayerPos[playerNum]=PlayerPos[1-playerNum];

PlayerPos[1-playerNum]=temp;

Console.WriteLine("玩家[{0}]与玩家[{1}]交换位置完成!按下任意键继续游戏",PlayerName[playerNum],PlayerName[1-playerNum]);

Console.ReadKey(true);

break;

elseif(input=="b")

Console.WriteLine("玩家[{0}]选择轰炸玩家[{1}]",PlayerName[playerNum],PlayerName[1-playerNum]);

PlayerPos[1-playerNum]-=6;

Console.WriteLine("玩家[{0}]被轰炸倒退6步!按下任意键继续游戏",PlayerName[1-playerNum]);

Console.ReadKey(true);

break;

else

input=Console.ReadLine();

break;

//踩到2地雷,直接倒退6格

case2:

Co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论