




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
第C#實現(xiàn)簡單的飛行棋游戲本文實例為大家分享了C#實現(xiàn)簡單飛行棋游戲的具體代碼,供大家參考,具體內容如下
下面展示完整代碼:
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ù)字與特殊字符的轉換
////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ù)組轉換為特殊字符
////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
///游戲進行代碼段
////summary
///paramname="playerNumber"/param
publicstaticvoidPlayGame(intplayerNumber)
Randomr=newRandom();
Console.WriteLine("{0}按任意鍵開始擲骰子",PlayerName[playerNumber]);
Console.ReadKey(true);
intn=r.Next(1,7);
Console.WriteLine("{0}擲出了{1}",PlayerName[playerNumber],n);
PlayerPos[playerNumber]+=n;
ChangePos();
Console.ReadKey(true);
Console.WriteLine("{0}按任意鍵開始行動",PlayerName[playerNumber]);
Console.ReadKey(true);
Console.WriteLine("{0}行動結束",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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆河北省石家莊市新樂培英中學高一化學第二學期期末綜合測試試題含解析
- 園區(qū)管理辦法教案小班
- 機場應急預案管理辦法
- 智能投顧技術演進-洞察及研究
- 建筑文明施工方案
- 發(fā)票管理辦法發(fā)票使用
- 變電站電氣安裝施工指導書
- 土壤腐殖質電化學特性表征技術及其環(huán)境效應研究
- 公益科技項目管理辦法
- 公園設施維修管理辦法
- DB11T 854-2023 占道作業(yè)交通安全設施設置技術要求
- 顧客滿意度調查表(模板)
- 礦山生產(chǎn)建設規(guī)模分類一覽表
- JJG 966-2010手持式激光測距儀
- FZ/T 01118-2012紡織品防污性能的檢測和評價易去污性
- 2020年廣州市初三英語中考模擬考試+答案
- 2023年心肺復蘇(CPR)指南解讀
- 電廠新員工安規(guī)考試
- 西方管理學名著提要
- 閥門設計計算書(帶公式)
- 新蘇科版七年級下冊初中數(shù)學全冊教案
評論
0/150
提交評論