




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第C#實現(xiàn)簡單的飛行棋游戲本文實例為大家分享了C#實現(xià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
///游戲開始提示
////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("請輸入玩家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[0]==PlayerName[1])
if(PlayerName[1]=="")
Console.WriteLine("玩家姓名不能為空,請重新輸入");
else
Console.WriteLine("兩個玩家姓名不能保持一致,請重新輸入玩家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
///實現(xiàn)數(shù)字與特殊字符的轉(zhuǎn)換
////summary
publicstaticvoidDrawMap()
inti;
Console.WriteLine("幸運圓盤:①\t炸彈:★\t暫停:▲\t時空隧道:﹌");
#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;//幸運圓盤
case2:
Console.ForegroundColor=ConsoleColor.Cyan;
str="★";
break;//地雷
case3:
Console.ForegroundColor=ConsoleColor.Gray;
str="▲";
break;//暫停
case4:
Console.ForegroundColor=ConsoleColor.Green;
str="﹌";
break;//時空隧道
returnstr;
///summary
///游戲進(jìn)行代碼段
////summary
///paramname="playerNumber"/param
publicstaticvoidPlayGame(intplayerNumber)
Randomr=newRandom();
Console.WriteLine("{0}按任意鍵開始擲骰子",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}按任意鍵開始行動",PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行動結(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}踩到了幸運圓盤,有以下兩個選擇:1.雙方交換位置,2.對方后退六格",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}選擇轟炸對方",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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二網(wǎng)銷售培訓(xùn)體系構(gòu)建
- 超市員工溝通培訓(xùn)
- 地下水水文地質(zhì)工程地質(zhì)重點基礎(chǔ)知識點
- 培訓(xùn)課件花卉生產(chǎn)管理
- 道路事故協(xié)議書范本
- 變電運維系統(tǒng)培訓(xùn)大綱
- 退款售后協(xié)議書范本
- 智能制造協(xié)議書
- 轉(zhuǎn)讓平板木床合同協(xié)議
- 郵件自取協(xié)議書范本
- 預(yù)錄用協(xié)議勞動合同
- GA/T 751-2024公安視頻圖像屏幕顯示信息疊加規(guī)范
- 新疆烏魯木齊市名校2025屆初三5月中考模擬考試數(shù)學(xué)試題試卷含解析
- 2025至2030中國長鏈氯化石蠟行業(yè)供需現(xiàn)狀與前景策略研究報告
- 租地蓋大棚合同協(xié)議
- 自體輸血知識培訓(xùn)課件
- 人教A版高一下冊必修第二冊高中數(shù)學(xué)8.6.2直線與平面垂直【課件】
- 戀愛協(xié)議書違約合同
- 薪酬管理制度框架搭建
- 軟件開發(fā)行業(yè)智能化軟件開發(fā)方案
- 2025年全國中小學(xué)校學(xué)生禁毒知識競賽題庫及答案(共370題)
評論
0/150
提交評論