




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第C#控制臺(tái)實(shí)現(xiàn)簡(jiǎn)單飛行棋游戲本文實(shí)例為大家分享了C#控制臺(tái)實(shí)現(xiàn)簡(jiǎn)單飛行棋游戲的具體代碼,供大家參考,具體內(nèi)容如下
需求分析
1.制作游戲頭部:游戲頭部介紹
2.繪制地圖
使用一維數(shù)組裝整個(gè)地圖的路線
如果這個(gè)位置是0,繪制普通格子□
如果這個(gè)位置是1,繪制幸運(yùn)輪盤(pán)◎
如果這個(gè)位置是2,繪制地雷★
如果這個(gè)位置是3,繪制暫?!?/p>
如果這個(gè)位置是4,繪制時(shí)空隧道卍
規(guī)劃幸運(yùn)輪盤(pán)位置
int[]luckyturn={6,23,40,55,69,83};
規(guī)劃地雷的位置
int[]landMine={5,13,17,33,38,50,64,80,94};
規(guī)劃暫停位置
int[]pause={9,27,60,93};
規(guī)劃時(shí)空隧道的位置
int[]timeTunnel={20,25,45,63,72,88,90};
3.設(shè)置特殊關(guān)卡
代碼如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Threading.Tasks;
namespace_01飛行棋
classProgram
///summary
///整個(gè)地圖數(shù)組
////summary
staticint[]Maps=newint[100];
///summary
///存儲(chǔ)玩家的數(shù)組
////summary
staticint[]PlayerPos=newint[2];
///summary
///玩家名稱(chēng)的數(shù)組
////summary
staticstring[]PlayerName=newstring[2];
staticbool[]PlayerFlage=newbool[2];
staticvoidMain(string[]args)
//繪制游戲標(biāo)題
ShowTitle();
//輸入玩家名稱(chēng)
Console.WriteLine("請(qǐng)輸入玩家A的姓名:");
PlayerName[0]=Console.ReadLine();
while(PlayerName[0]=="")
Console.WriteLine("玩家A的姓名不能為空,請(qǐng)重新輸入!");
PlayerName[0]=Console.ReadLine();
Console.WriteLine("請(qǐng)輸入玩家B的姓名:");
PlayerName[1]=Console.ReadLine();
while(PlayerName[1]==""||PlayerName[1]==PlayerName[0])
if(PlayerName[1]=="")
Console.WriteLine("玩家B的姓名不能為空,請(qǐng)重新輸入!");
PlayerName[1]=Console.ReadLine();
if(PlayerName[1]==PlayerName[0])
Console.WriteLine("玩家B的姓名和A重復(fù),請(qǐng)重新輸入!");
PlayerName[1]=Console.ReadLine();
//輸入完姓名,清空屏幕
Console.Clear();
ShowTitle();
//初始化地圖關(guān)卡
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
///設(shè)置游戲標(biāo)題
////summary
staticvoidShowTitle()
//設(shè)置顏色
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
///初始化地圖關(guān)卡
////summary
staticvoidInitialMap()
//確定幸運(yùn)輪盤(pán)的位置◎==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;
//確定時(shí)空隧道的位置卍==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("游戲規(guī)則:");
Console.WriteLine("1.兩名玩家輪流擲骰子,規(guī)定A玩家先擲.");
Console.WriteLine("2.踩到□格子安全,沒(méi)有獎(jiǎng)懲!");
Console.WriteLine("3.踩到◎幸運(yùn)輪盤(pán),可以進(jìn)行兩種選擇:a.置換與對(duì)方玩家的位置;b.進(jìn)行轟炸對(duì)方,使對(duì)方倒退6步");
Console.WriteLine("4.踩到★地雷,倒退6步!");
Console.WriteLine("5.踩到▲暫停,下個(gè)回合將暫停操作!");
Console.WriteLine("6.踩到卍時(shí)空隧道,直接前進(jìn)10步!");
Console.WriteLine("7.如果踩到對(duì)方,則對(duì)方直接退6步!");
///第一橫行
for(inti=0;ii++)
//判斷兩個(gè)玩家的位置一樣,確定兩個(gè)玩家還都在地圖中
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;
//游戲環(huán)節(jié)
staticvoidPlayGame(intplayerNum)
Randomr=newRandom();
Console.WriteLine("玩家[{0}]按下任意鍵擲骰子.",PlayerName[playerNum]);
Console.ReadKey(true);
intnumber=r.Next(1,7);
Console.WriteLine("玩家[{0}]擲出{1}點(diǎn).",PlayerName[playerNum],number);
Console.WriteLine("玩家[{0}]按下任意鍵進(jìn)行移動(dòng).",PlayerName[playerNum]);
Console.ReadKey(true);
PlayerPos[playerNum]+=number;
Console.WriteLine("玩家[{0}]移動(dòng)完成!",PlayerName[playerNum]);
//玩家踩到對(duì)方
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]])
//踩到普通地板,安全沒(méi)有獎(jiǎng)懲
case0:
Console.WriteLine("玩家[{0}]踩到安全地帶,沒(méi)有獎(jiǎng)懲!按下任意鍵繼續(xù)游戲",PlayerName[playerNum]);
Console.ReadKey(true);
break;
//踩到1幸運(yùn)輪盤(pán),選擇獎(jiǎng)勵(lì)
case1:
Console.WriteLine("玩家[{0}]踩到幸運(yùn)輪盤(pán),請(qǐng)選擇:a--交換位置b--轟炸對(duì)方.",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}]交換位置完成!按下任意鍵繼續(xù)游戲",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步!按下任意鍵繼續(xù)游戲",PlayerName[1-playerNum]);
Console.ReadKey(true);
break;
else
input=Console.ReadLine();
break;
//踩到2地雷,直接倒退6格
case2:
Co
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年衛(wèi)生保健理論知識(shí)考核試題題庫(kù)及答案
- 2025年住院醫(yī)師規(guī)范培訓(xùn)(各省)-江蘇住院醫(yī)師醫(yī)學(xué)檢驗(yàn)科歷年參考題庫(kù)含答案解析(5套典型題)
- 2025年住院醫(yī)師規(guī)范培訓(xùn)(各省)-上海住院醫(yī)師神經(jīng)內(nèi)科歷年參考題庫(kù)含答案解析(5套典型題)
- 2025年企業(yè)文化企業(yè)建設(shè)知識(shí)競(jìng)賽-正大集團(tuán)動(dòng)保人員知識(shí)競(jìng)賽歷年參考題庫(kù)含答案解析(5套典型題)
- 2025年企業(yè)文化企業(yè)建設(shè)知識(shí)競(jìng)賽-中交二航局六公司設(shè)備管理知識(shí)競(jìng)賽歷年參考題庫(kù)含答案解析(5套典型題)
- 2025年專(zhuān)升本考試-專(zhuān)升本考試(三維設(shè)計(jì))歷年參考題庫(kù)含答案解析(5套典型題)
- 高校教學(xué)評(píng)估匯報(bào)材料
- 防汛準(zhǔn)備工作匯報(bào)
- 技術(shù)專(zhuān)家的局限與應(yīng)對(duì)
- 電梯自檢報(bào)告講解
- 養(yǎng)老機(jī)構(gòu)醫(yī)養(yǎng)結(jié)合交流合作總結(jié)范文
- 美團(tuán)2024年社會(huì)責(zé)任報(bào)告 -esg
- 協(xié)同oa系統(tǒng)管理辦法
- 骨科VTE的預(yù)防及護(hù)理
- 工貿(mào)行業(yè)重大事故隱患判定標(biāo)準(zhǔn)安全試題及答案
- 2025年山東威海中考數(shù)學(xué)試卷真題及答案詳解(精校打印版)
- 2025年中國(guó)環(huán)烷基變壓器油行業(yè)市場(chǎng)調(diào)查、投資前景及策略咨詢(xún)報(bào)告
- 新生兒甲狀腺低下及護(hù)理
- 2025年全國(guó)新高考I卷高考全國(guó)一卷真題語(yǔ)文試卷(真題+答案)
- 信息費(fèi)合同協(xié)議書(shū)范本
- 超市外租區(qū)租賃合同3篇
評(píng)論
0/150
提交評(píng)論