




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
第C#實現(xiàn)winform版飛行棋Panelmap=newPanel();//創(chuàng)建游戲區(qū)對象
int[]mapList=newint[390];//存儲地圖數(shù)的數(shù)組
PictureBox[]mapImg=newPictureBox[390];//存儲圖片的數(shù)組
constintsize=30;//格子大小
LabeljiLu=newLabel();
RichTextBoxmsg=newRichTextBox();//存儲近況
Randomr=newRandom();
PictureBoxdice=newPictureBox();//創(chuàng)建骰子對象
PanelredplayHome=newPanel();//紅方飛機(jī)
PanelgreenplayHome=newPanel();//綠方飛機(jī)
privatevoidForm1_Load(objectsender,EventArgse)
//設(shè)置不可移動
this.FormBorderStyle=FormBorderStyle.FixedSingle;
//this.FormBorder"../../img/select_circle.png");
redplayHome.Location=newPoint(20,map.Top-120);
redplayHome.BackgroundImageLayout=ImageLayout.Stretch;
this.Controls.Add(redplayHome);
//綠方的家
greenplayHome.Size=newSize(100,100);
greenplayHome.BackgroundImage=Image.FromFile("../../img/select_circle.png");
greenplayHome.Location=newPoint(map.Left+map.Width-greenplayHome.Width,map.Top-120);
greenplayHome.BackgroundImageLayout=ImageLayout.Stretch;
this.Controls.Add(greenplayHome);
//紅飛機(jī)
PictureBoxredPlayer=newPictureBox();
redPlayer.Size=newSize(80,80);
redPlayer.Image=Image.FromFile("../../img/red.png");
redPlayer.Location=newPoint(10,10);
redPlayer.SizeMode=PictureBoxSizeMode.StretchImage;
redplayHome.Controls.Add(redPlayer);
//綠飛機(jī)
PictureBoxgreenPlayer=newPictureBox();
greenPlayer.Size=newSize(80,80);
greenPlayer.Image=Image.FromFile("../../img/green.png");
greenPlayer.Location=newPoint(10,10);
greenPlayer.SizeMode=PictureBoxSizeMode.StretchImage;
greenplayHome.Controls.Add(greenPlayer);
//記錄游戲近況框
msg.Size=newSize(260,390);
msg.ReadOnly=true;//設(shè)置只讀
msg.Location=newPoint(map.Right,map.Top);
msg.Font=newFont("微軟雅黑",12);
msg.BackColor=Color.LightPink;
this.Controls.Add(msg);
//游戲近況字
jiLu.Size=newSize(100,30);
jiLu.Text="游戲近況";
jiLu.Font=newFont("楷體",16);
jiLu.ForeColor=Color.Maroon;
jiLu.BackColor=Color.Aquamarine;
jiLu.Location=newPoint(msg.Left+msg.Width/2-jiLu.Width/2,map.Top-jiLu.Height);
this.Controls.Add(jiLu);
//骰子
dice.Size=newSize(100,100);
dice.Image=Image.FromFile("../../img/roll.png");
dice.Location=newPoint(map.Left+map.Width/2-dice.Width/2,map.Top-dice.Height);
dice.SizeMode=PictureBoxSizeMode.StretchImage;
this.Controls.Add(dice);
dice.MouseClick+=Dice_MouseClick;
stringstartmsg="請兩個人先輪流擲骰子,點大的先一步,紅方先手";
ResultTell(startmsg);//調(diào)用
//骰子點擊事件
privatevoidDice_MouseClick(objectsender,MouseEventArgse)
PlayDice();
PlayGame();
//記錄誰可以投擲索引0代表紅方,1代表綠方
bool[]whoCan=newbool[2]{true,false};
int[]startNum=newint[2];//記錄雙方投擲的點數(shù)
string[]playeName=newstring[2]{"紅方","綠方"};
int[]playPostion=newint[2]{-1,-1};//記錄兩個人現(xiàn)在位置沒有出門默認(rèn)-1
int[]playStan=newint[2]{-1,-1};//記錄上飛機(jī)上一個位置的坐標(biāo)索引默認(rèn)為-1
privatevoidPlayDice()//輪流投擲的方法此方法為投擲為一輪
//紅方先投默認(rèn)紅方先投擲
if(whoCan[0])//默認(rèn)為true
startNum[0]=r.Next(1,7);
ResultTell(string.Format("紅方投擲出【{0}】點",startNum[0]));
whoCan[0]=!whoCan[0];//false賦給紅方
else
whoCan[0]=!whoCan[0];//將false變?yōu)閠rue
//綠方投擲
if(whoCan[1])//默認(rèn)為false
startNum[1]=r.Next(1,7);
ResultTell(string.Format("綠方投擲出【{0}】點",startNum[1]));
whoCan[1]=!whoCan[1];//將true變?yōu)閒alse
else
whoCan[1]=!whoCan[1];//將true變?yōu)閒alse
//控制游戲剛開始誰先行
boolstart=true;
//判斷是不是游戲剛開始,比點數(shù)確定先行
privatevoidPlayGame()
//判斷是否投擲完一輪,投擲完一輪后才能判斷點數(shù)誰先行
if(start)
//雙方都投擲后,點數(shù)都相同的情況
OutDoor();
if(whoCan[0]!whoCan[1])//truetrue
ResultTell("請紅方投擲");
elseif(!whoCan[0]whoCan[1])//falsetrue
ResultTell("請綠方投擲");
else
{//判斷誰變成false,說明上次是誰投擲的
if(whoCan[0]!whoCan[1])//綠方
PlayeReturn(1);
elseif(!whoCan[0]whoCan[1])//紅方
PlayeReturn(0);
//是否暫停判斷
bool[]reclick=newbool[2]{false,false};
//雙方開始游戲,playIndex為索引0,1來判斷是紅方還是綠方
privatevoidPlayeReturn(intplayIndex)
{//判斷此方位置為-1,則沒有出發(fā)
if(playPostion[playIndex]==-1)
switch(startNum[playIndex])//判斷點數(shù)2,4,6可以出發(fā)
case2:
case4:
ResultTell(string.Format("{0}可以起步!",playeName[playIndex]));
playPostion[playIndex]=0;//初始到開始位置
playStan[playIndex]=0;//存儲上一次位置
//如果位置相同換兩個飛機(jī)的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應(yīng)的圖片
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
break;
case6:
whoCan[playIndex]=true;//此方重新投擲
whoCan[1-playIndex]=false;//對方不投擲
ResultTell(string.Format("{0}可以起步!",playeName[playIndex]));
playPostion[playIndex]=0;//初始到索引為0處
playStan[playIndex]=0;//數(shù)組存儲上一次位置為0
//如果位置相同換兩個飛機(jī)的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應(yīng)的圖片
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
ResultTell(string.Format("請{0}投擲骰子",playeName[playIndex]));
break;
default:
ResultTell(string.Format("很遺憾,{0}投擲出{1}點無法起步!輪到{2}投擲",playeName[playIndex],startNum[playIndex],playeName[1-playIndex]));
break;
if(playPostion[0]!=-1)//紅色出門
redplayHome.Controls.Clear();//紅色飛機(jī)的家中飛機(jī)消失
if(playPostion[1]!=-1)//綠色出門
greenplayHome.Controls.Clear();//綠色飛機(jī)的家中飛機(jī)消失
else//不是-1則已經(jīng)出發(fā)
//將現(xiàn)在位置賦給記錄上一次位置的數(shù)組中
playStan[playIndex]=playPostion[playIndex];
playPostion[playIndex]+=startNum[playIndex];//將點數(shù)賦給位置
ResultTell(string.Format("{0}移動{1}步",playeName[playIndex],startNum[playIndex]));
if(playPostion[playIndex]=99)
ResultTell(string.Format("{0}獲勝!",playeName[playIndex]));
playPostion[playIndex]=99;
ChangImg(playIndex);
return;
ChangImg(playIndex);//改變圖片
//判斷移動完后位置
if(playPostion[playIndex]==playPostion[1-playIndex])
playPostion[1-playIndex]=0;
ResultTell(string.Format("厲害!{0}精準(zhǔn)踩到{1},{0}的當(dāng)前位置是{2},{1}的當(dāng)前位置是{3}",playeName[playIndex],playeName[1-playIndex],playPostion[playIndex],playPostion[1-playIndex]));
playStan[1-playIndex]=playPostion[1-playIndex];
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[1-playIndex];
mapImg[road[playPostion[1-playIndex]]].Image=imageList1.Images[1-playIndex];
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
switch(mapList[road[playPostion[playIndex]]])
case1://走到索引為1的地圖上時
ResultTell(string.Format("{0}安全到達(dá)!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case2://香蕉皮
ResultTell(string.Format("很不幸,{0}踩中香蕉皮,退6步!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
playStan[playIndex]=playPostion[playIndex];
//記錄當(dāng)前的位置到上次位置數(shù)組中
playPostion[playIndex]-=6;//現(xiàn)在的位置后退6步
ChangImg(playIndex);//添加對應(yīng)的圖片
ResultTell(string.Format("{0}當(dāng)前的位置是{1}",playeName[playIndex],playPostion[playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case3://時空隧道
ResultTell(string.Format("恭喜!{0}踩中時空隧道,前進(jìn)6步!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
playStan[playIndex]=playPostion[playIndex];//將現(xiàn)在坐標(biāo)存儲到記錄上位置的數(shù)組中
playPostion[playIndex]+=6;//現(xiàn)在的位置后退6步
ChangImg(playIndex);//添加對應(yīng)的圖片
ResultTell(string.Format("{0}當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case4://陷阱
ResultTell(string.Format("可惜!{0}踩中陷阱,暫停一回合!",playeName[playIndex]));
reclick[1-playIndex]=true;
reclick[playIndex]=false;
break;
case5://幸運(yùn)星
ResultTell(string.Format("恭喜!踩中幸運(yùn)星,再玩一回合!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
whoCan[playIndex]=true;//開啟繼續(xù)搖骰子
whoCan[1-playIndex]=false;
ResultTell(string.Format("{0}繼續(xù)投擲。",playeName[playIndex]));
break;
case6://大羅移
ResultTell(string.Format("恭喜!{0}踩中大羅移,請選擇是否移動!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
DialogResultdr=MessageBox.Show("是否選擇移動!","大羅移!",MessageBoxButtons.YesNo);
if(dr==DialogResult.Yes)
{//雙方位置互換
inttemp=playPostion[playIndex];
playPostion[playIndex]=playPostion[1-playIndex];
playPostion[1-playIndex]=temp;
playStan[playIndex]=playPostion[playIndex];//將此方現(xiàn)在位置賦給記錄上次位置的數(shù)組
playStan[1-playIndex]=playPostion[1-playIndex];//將另一方現(xiàn)在的位置賦給記錄上次位置的數(shù)組
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
mapImg[road[playPostion[1-playIndex]]].Image=imageList1.Images[1-playIndex];
ResultTell(string.Format("{0}的當(dāng)前位置是{1},{2}的當(dāng)前位置是{3}",playeName[playIndex],playPostion[playIndex],playeName[1-playIndex],playPostion[1-playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case7://手槍
ResultTell(string.Format("恭喜!{0}獲得手槍,可選擇擊退對方3步!當(dāng)前位置是{1}",playeName[playIndex],playPostion[playIndex]));
DialogResultdrr=MessageBox.Show("是否選擇擊退對方!","手槍!",MessageBoxButtons.YesNo);
if(drr==DialogResult.Yes)
playStan[1-playIndex]=playPostion[1-playIndex];//記錄對方位置
playPostion[1-playIndex]-=3;//對方現(xiàn)在位置后移3個
mapImg[road[playPostion[1-playIndex]]].Image=imageList1.Images[1-playIndex];//添加圖片
ChangImg(1-playIndex);
ResultTell(string.Format("{0}被擊退對方3步!當(dāng)前位置是{1}",playeName[1-playIndex],playPostion[1-playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
第一輪:↓
紅色踩到后:reclick[0紅色]=reclick=false;reclick[1綠色]=reclick=true;
此時紅色搖完,綠色搖whcan[0]=false,whcan[1]=true;
reclick[playIndex]!reclick[1-playIndex]=true:false;
第二輪↓
reclick[1綠色]=reclick=true;reclick[0紅色]=reclick=false;
whcan[0]=true,whcan[1]=false;
reclick[playIndex==綠色]!reclick[1-playIndex==紅色]=true:false;
if(reclick[playIndex]!reclick[1-playIndex])
whoCan[playIndex]=true;
whoCan[1-playIndex]=false;
reclick[playIndex]=false;
reclick[playIndex]=false;
*第二輪結(jié)束
whcan[0]=false,whcan[1]=true;
第三輪開始
whcan[0]=false,whcan[1]=true;
//三輪結(jié)束
whcan[0]=true,whcan[1]=false;
privatevoidChangImg(intplayIndex)
//如果位置相同換成兩個飛機(jī)的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應(yīng)的圖片
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
//雙方已經(jīng)出發(fā),兩個人在同一位置,此方圖片離開后,顯示另一方圖片
if(playStan[0]==playStan[1]playStan[0]!=-1playStan[0]!=-1)//如果上次位置雙方相同
mapImg[road[playStan[playIndex]]].Image=imageList1.Images[1-playIndex];
else//上次雙方位置不同,變?yōu)橹澳J(rèn)的圖片
switch(mapList[road[playStan[playIndex]]])//判斷上一次記錄的圖片
case0://地板
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/floor.png");
break;
case1://路
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/water.gif");
break;
case2://香蕉皮
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/xj.jpg");
break;
case3://時空
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/sk.jpg");
break;
case4://陷阱
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/xianjing.jpg");
break;
case5://星星
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/xx.jpg");
break;
case6://交換
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/jh.jpg");
break;
case7://手槍
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/sq.jpg");
break;
case10://開始位置
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/game-out.jpg");
break;
case11://結(jié)束位置
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/game-over.jpg");
break;
default:
break;
//判斷投擲完一輪,相同點數(shù),誰點數(shù)大誰再投擲
privatevoidOutDoor()
//投擲完一輪,并且雙方都存有點數(shù)
if(whoCan[0]!whoCan[1](startNum[0]!=0||startNum[1]!=0))
{//雙方點數(shù)相同
if(startNum[0].Equals(startNum[1]))
ResultTell("雙方點數(shù)相同,請重新投擲!");
else
start=false;//不是第一回合
if(startNum[0]startNum[1])
ResultTell("紅方點數(shù)較大,先行一步,紅方投擲");
whoCan[0]=true;//紅方繼續(xù)投擲
whoCan[1]=false;
else
ResultTell("綠方點數(shù)較大,先行一步,綠方投擲");
whoCan[0]=false;
whoCan[1]=true;//綠方繼續(xù)投擲
voidInitialGame()//初始化地圖
for(inti=0;imapImg.Length;i++)
CreateMap();//調(diào)用存儲數(shù)字的圖片
CreateGear();//調(diào)用創(chuàng)建機(jī)關(guān)的方法必須向有路,才能調(diào)用機(jī)關(guān)的方法
PictureBoxpicture=newPictureBox();
picture.Size=newSize(size,size);
mapImg[i]=picture;//圖片添加到數(shù)組
switch(mapList[i])//判斷地圖數(shù)組中存儲的數(shù)字,添加圖片
case0://地板
picture.Image=Image.FromFile("../../img/floor.png");
break;
case1://路
picture.Image=Image.FromFile("../../img/water.gif");
break;
case2://香蕉皮
picture.Image=Image.FromFile("../../img/xj.jpg");
break;
case3://時空
picture.Image=Image.FromFile("../../img/sk.jpg");
break;
case4://陷阱
picture.Image=Image.FromFile("../../img/xianjing.jpg");
break;
case5://星星
picture.Image=Image.FromFile("../../img/xx.jpg");
break;
case6://交換
picture.Image=Image.FromFile("../../img/jh.jpg");
break;
case7://手槍
picture.Image=Image.FromFile("../../img/sq.jpg");
break;
case10://開始位置
picture.Image=Image.FromFile("../../img/game-out.jpg");
break;
case11://結(jié)束位置
picture.Image=Image.FromFile("../../img/game-over.jpg");
break;
default:
break;
picture.SizeMode=PictureBoxSizeMode.StretchImage;//圖片適應(yīng)大小
picture.Location=newPoint(i%30*size,i/30*size);
map.Controls.Add(picture);//圖片添加到地圖中
voidCreateMap()//創(chuàng)建地圖
CreateRoed();//創(chuàng)建路
for(inti=0;iroad.Length;i++)
mapList[road[i]]=1;//路將路對應(yīng)的索引變?yōu)?
mapList[0]=10;//開始位置
mapList[
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 充分準(zhǔn)備的行政組織理論試題及答案
- 西藥批發(fā)企業(yè)客戶關(guān)系管理策略與實施考核試卷
- 嵌入式開發(fā)考試案例解析試題及答案
- 行政組織理論的實踐性分析與2025年試題及答案
- 四級軟件測試職業(yè)生涯規(guī)劃試題及答案
- 軟件測試工程師考試常見問題試題及答案
- 嵌入式系統(tǒng)的故障排除指南試題及答案
- 疾病預(yù)防控制檢測考核試卷
- 油品質(zhì)量分析與檢測技術(shù)考核試卷
- 開發(fā)中的最佳實踐試題及答案
- CO催化偶聯(lián)制草酸二甲酯反應(yīng)機(jī)理、催化劑和動力學(xué)的研究
- DL5190.5-2019電力建設(shè)施工技術(shù)規(guī)范第5部分:管道及系統(tǒng)
- 銀川市第三中學(xué)2025屆高一數(shù)學(xué)第二學(xué)期期末預(yù)測試題含解析
- 2024火電機(jī)組金屬監(jiān)督工作任務(wù)表
- 抗凝藥術(shù)前停藥指南
- 中國血脂管理指南(基層版2024年)
- QBT 2959-2008 鋼板網(wǎng)行業(yè)標(biāo)準(zhǔn)
- 大學(xué)生安全教育-知到答案、智慧樹答案
- 走進(jìn)歌劇世界智慧樹知到期末考試答案章節(jié)答案2024年北京航空航天大學(xué)
- 口腔實習(xí)生培訓(xùn)
- DL-T 5148-2021水工建筑物水泥灌漿施工技術(shù)條件-PDF解密
評論
0/150
提交評論