




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第C#實(shí)現(xiàn)簡(jiǎn)單的飛行棋游戲本文實(shí)例為大家分享了C#實(shí)現(xiàn)簡(jiǎn)單飛行棋游戲的具體代碼,供大家參考,具體內(nèi)容如下
下面展示完整代碼:
namespace飛行棋
classProgram
publicstaticint[]Maps=newint[100];
publicstaticint[]PlayerPos=newint[2];
publicstaticstring[]PlayerName=newstring[2];
publicstaticbool[]Flags=newbool[2];//初值為false
staticvoidMain(string[]args)
GameStart();
Mes();
Console.Clear();
GameStart();
Console.WriteLine("{0}的士兵用A表示\n{1}的士兵用A表示",PlayerName[0],PlayerName[1]);
InitailMap();
DrawMap();
while(PlayerPos[0]99PlayerPos[1]99)
for(inti=0;ii++)
if(!Flags[i])
PlayGame(i);
else
Flags[i]=false;
if(PlayerPos[i]=99)
Console.WriteLine("玩家{0}勝利",PlayerName[i]);
Win();
Console.ReadKey();
///summary
///游戲開(kāi)始提示
////summary
publicstaticvoidGameStart()
Console.ForegroundColor=ConsoleColor.Blue;
Console.WriteLine("************************");
Console.ForegroundColor=ConsoleColor.Yellow;
Console.WriteLine("************************");
Console.ForegroundColor=ConsoleColor.Green;
Console.WriteLine("*********飛行棋*********");
Console.ForegroundColor=ConsoleColor.Magenta;
Console.WriteLine("************************");
Console.ForegroundColor=ConsoleColor.Gray;
Console.WriteLine("************************");
///summary
///玩家信息輸入
////summary
publicstaticvoidMes()
Console.WriteLine("請(qǐng)輸入玩家A的姓名");
PlayerName[0]=Console.ReadLine();
while(PlayerName[0]=="")
Console.WriteLine("玩家姓名不能為空,請(qǐng)重新輸入玩家A的姓名");
PlayerName[0]=Console.ReadLine();
Console.WriteLine("請(qǐng)輸入玩家B的姓名");
PlayerName[1]=Console.ReadLine();
while(PlayerName[1]==""||PlayerName[0]==PlayerName[1])
if(PlayerName[1]=="")
Console.WriteLine("玩家姓名不能為空,請(qǐng)重新輸入");
else
Console.WriteLine("兩個(gè)玩家姓名不能保持一致,請(qǐng)重新輸入玩家B的姓名");
PlayerName[0]=Console.ReadLine();
///summary
///初始化地圖
////summary
publicstaticvoidInitailMap()
int[]luckyturn={6,23,40,55,69,83};
int[]landMine={5,13,17,33,38,50,55,80,94};
int[]pause={9,27,60,93};
int[]timeTunnel={20,25,45,63,72,88,90};
foreach(intiinluckyturn)
Maps[i]=1;
foreach(intiinlandMine)
Maps[i]=2;
foreach(intiinpause)
Maps[i]=3;
foreach(intiintimeTunnel)
Maps[i]=4;
///summary
///實(shí)現(xiàn)數(shù)字與特殊字符的轉(zhuǎn)換
////summary
publicstaticvoidDrawMap()
inti;
Console.WriteLine("幸運(yùn)圓盤(pán):①\t炸彈:★\t暫停:▲\t時(shí)空隧道:﹌");
#region第一橫行
for(i=0;ii++)
Console.Write(Draw(i));
Console.WriteLine();
#endregion
#region第一豎行
for(;ii++)
for(intj=0;jj++)
Console.Write("");
Console.WriteLine(Draw(i));
#endregion
#region第二橫行
for(i=64;i=35;i--)
Console.Write(Draw(i));
Console.WriteLine();
#endregion
#region第二豎行
for(i=65;ii++)
Console.WriteLine(Draw(i));
//Console.WriteLine();
#endregion
#region第三橫行
for(;ii++)
Console.Write(Draw(i));
#endregion
Console.WriteLine();
///summary
///將數(shù)組轉(zhuǎn)換為特殊字符
////summary
///paramname="i"/param
///returns/returns
publicstaticstringDraw(inti)
stringstr="";
if(PlayerPos[0]==PlayerPos[1]PlayerPos[1]==i)
Console.ForegroundColor=ConsoleColor.DarkRed;
str="";
elseif(PlayerPos[0]==i)
Console.ForegroundColor=ConsoleColor.DarkRed;
str="A";
elseif(PlayerPos[1]==i)
Console.ForegroundColor=ConsoleColor.DarkRed;
str="B";
else
switch(Maps[i])
case0:
Console.ForegroundColor=ConsoleColor.Yellow;
str="▅";
break;
case1:
Console.ForegroundColor=ConsoleColor.Blue;
str="①";
break;//幸運(yùn)圓盤(pán)
case2:
Console.ForegroundColor=ConsoleColor.Cyan;
str="★";
break;//地雷
case3:
Console.ForegroundColor=ConsoleColor.Gray;
str="▲";
break;//暫停
case4:
Console.ForegroundColor=ConsoleColor.Green;
str="﹌";
break;//時(shí)空隧道
returnstr;
///summary
///游戲進(jìn)行代碼段
////summary
///paramname="playerNumber"/param
publicstaticvoidPlayGame(intplayerNumber)
Randomr=newRandom();
Console.WriteLine("{0}按任意鍵開(kāi)始擲骰子",PlayerName[playerNumber]);
Console.ReadKey(true);
intn=r.Next(1,7);
Console.WriteLine("{0}擲出了{(lán)1}",PlayerName[playerNumber],n);
PlayerPos[playerNumber]+=n;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0}按任意鍵開(kāi)始行動(dòng)",PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行動(dòng)結(jié)束",PlayerName[playerNumber]);
Console.ReadKey(true);
if(PlayerPos[playerNumber]==PlayerPos[1-playerNumber])
Console.WriteLine("玩家{0}踩到了玩家{1},玩家{2}后退六格",PlayerName[playerNumber],PlayerName[1-playerNumber],PlayerName[1-playerNumber]);
PlayerPos[1]-=6;
Console.ReadKey(true);
else
switch(Maps[PlayerPos[playerNumber]])
case0:
Console.WriteLine("玩家{0}正常",PlayerName[playerNumber]);
Console.ReadKey(true);
break;
case1:
Console.WriteLine("玩家{0}踩到了幸運(yùn)圓盤(pán),有以下兩個(gè)選擇:1.雙方交換位置,2.對(duì)方后退六格",PlayerName[playerNumber]);
while(true)
stringinput=Console.ReadLine();
if(input=="1")
Console.WriteLine("玩家{0}選擇交換位置",PlayerName[playerNumber]);
Console.ReadKey(true);
inttemp;
temp=PlayerPos[playerNumber];
PlayerPos[playerNumber]=PlayerPos[1-playerNumber];
PlayerPos[1-playerNumber]=temp;
Console.WriteLine("交換成功,按任意鍵繼續(xù)游戲");
Console.ReadKey(true);
break;
elseif(input=="2")
Console.WriteLine("玩家{0}選擇轟炸對(duì)方",PlayerName[playerNumber]);
Console.ReadKey(true);
PlayerPos[1-playerNumber]-=6;
Console.ReadKey(true);
break;
else
Console.WriteLine("只能輸入1或者2");
Console.ReadKey(true);
break;
case2:
Console.WriteLine("玩家{0}踩到了地雷,退六格",PlayerName[playerNumber]);
Console.ReadKey(true);
PlayerPos[playerNumber]-=6;
break;
case3:
Console.WriteLine("玩家{0}踩到了暫停,暫停一回合",Playe
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國(guó)桑葉項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 中國(guó)肉用仔雞飼料項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 中國(guó)康復(fù)醫(yī)療機(jī)械項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 中國(guó)計(jì)算機(jī)系統(tǒng)排除故障項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 中國(guó)干香菇項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 中國(guó)鵝養(yǎng)殖業(yè)項(xiàng)目創(chuàng)業(yè)計(jì)劃書(shū)
- 乙炔鋼瓶試題及答案
- 樂(lè)山保安考試題及答案
- 家具定制配送安裝合同協(xié)議
- 小學(xué)五年級(jí)上冊(cè)作文
- 2025年新高考2卷(新課標(biāo)Ⅱ卷)英語(yǔ)試卷
- 2024年全國(guó)統(tǒng)一高考英語(yǔ)試卷(新課標(biāo)Ⅰ卷)含答案
- 人教版高一下學(xué)期期末考試數(shù)學(xué)試卷與答案解析(共五套)
- MOOC 思辨式英文寫(xiě)作-南開(kāi)大學(xué) 中國(guó)大學(xué)慕課答案
- T∕ACSC 01-2022 輔助生殖醫(yī)學(xué)中心建設(shè)標(biāo)準(zhǔn)(高清最新版)
- 個(gè)體化健康教育
- 《白內(nèi)障》ppt課件
- Resume(簡(jiǎn)歷英文版)
- 報(bào)價(jià)單模板(中英文
- 股骨頸骨折中醫(yī)診療方案
- 苯甲苯連續(xù)精餾裝置工藝設(shè)計(jì) 精餾塔設(shè)計(jì)說(shuō)明書(shū) 化工設(shè)計(jì)
評(píng)論
0/150
提交評(píng)論