




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
第C#實現winform版飛行棋Panelmap=newPanel();//創建游戲區對象
int[]mapList=newint[390];//存儲地圖數的數組
PictureBox[]mapImg=newPictureBox[390];//存儲圖片的數組
constintsize=30;//格子大小
LabeljiLu=newLabel();
RichTextBoxmsg=newRichTextBox();//存儲近況
Randomr=newRandom();
PictureBoxdice=newPictureBox();//創建骰子對象
PanelredplayHome=newPanel();//紅方飛機
PanelgreenplayHome=newPanel();//綠方飛機
privatevoidForm1_Load(objectsender,EventArgse)
//設置不可移動
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);
//紅飛機
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);
//綠飛機
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;//設置只讀
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);//調用
//骰子點擊事件
privatevoidDice_MouseClick(objectsender,MouseEventArgse)
PlayDice();
PlayGame();
//記錄誰可以投擲索引0代表紅方,1代表綠方
bool[]whoCan=newbool[2]{true,false};
int[]startNum=newint[2];//記錄雙方投擲的點數
string[]playeName=newstring[2]{"紅方","綠方"};
int[]playPostion=newint[2]{-1,-1};//記錄兩個人現在位置沒有出門默認-1
int[]playStan=newint[2]{-1,-1};//記錄上飛機上一個位置的坐標索引默認為-1
privatevoidPlayDice()//輪流投擲的方法此方法為投擲為一輪
//紅方先投默認紅方先投擲
if(whoCan[0])//默認為true
startNum[0]=r.Next(1,7);
ResultTell(string.Format("紅方投擲出【{0}】點",startNum[0]));
whoCan[0]=!whoCan[0];//false賦給紅方
else
whoCan[0]=!whoCan[0];//將false變為true
//綠方投擲
if(whoCan[1])//默認為false
startNum[1]=r.Next(1,7);
ResultTell(string.Format("綠方投擲出【{0}】點",startNum[1]));
whoCan[1]=!whoCan[1];//將true變為false
else
whoCan[1]=!whoCan[1];//將true變為false
//控制游戲剛開始誰先行
boolstart=true;
//判斷是不是游戲剛開始,比點數確定先行
privatevoidPlayGame()
//判斷是否投擲完一輪,投擲完一輪后才能判斷點數誰先行
if(start)
//雙方都投擲后,點數都相同的情況
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,則沒有出發
if(playPostion[playIndex]==-1)
switch(startNum[playIndex])//判斷點數2,4,6可以出發
case2:
case4:
ResultTell(string.Format("{0}可以起步!",playeName[playIndex]));
playPostion[playIndex]=0;//初始到開始位置
playStan[playIndex]=0;//存儲上一次位置
//如果位置相同換兩個飛機的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應的圖片
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;//數組存儲上一次位置為0
//如果位置相同換兩個飛機的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應的圖片
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();//紅色飛機的家中飛機消失
if(playPostion[1]!=-1)//綠色出門
greenplayHome.Controls.Clear();//綠色飛機的家中飛機消失
else//不是-1則已經出發
//將現在位置賦給記錄上一次位置的數組中
playStan[playIndex]=playPostion[playIndex];
playPostion[playIndex]+=startNum[playIndex];//將點數賦給位置
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}精準踩到{1},{0}的當前位置是{2},{1}的當前位置是{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}安全到達!當前位置是{1}",playeName[playIndex],playPostion[playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case2://香蕉皮
ResultTell(string.Format("很不幸,{0}踩中香蕉皮,退6步!當前位置是{1}",playeName[playIndex],playPostion[playIndex]));
playStan[playIndex]=playPostion[playIndex];
//記錄當前的位置到上次位置數組中
playPostion[playIndex]-=6;//現在的位置后退6步
ChangImg(playIndex);//添加對應的圖片
ResultTell(string.Format("{0}當前的位置是{1}",playeName[playIndex],playPostion[playIndex]));
ResultTell(string.Format("{0}開始投擲。",playeName[1-playIndex]));
break;
case3://時空隧道
ResultTell(string.Format("恭喜!{0}踩中時空隧道,前進6步!當前位置是{1}",playeName[playIndex],playPostion[playIndex]));
playStan[playIndex]=playPostion[playIndex];//將現在坐標存儲到記錄上位置的數組中
playPostion[playIndex]+=6;//現在的位置后退6步
ChangImg(playIndex);//添加對應的圖片
ResultTell(string.Format("{0}當前位置是{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://幸運星
ResultTell(string.Format("恭喜!踩中幸運星,再玩一回合!當前位置是{1}",playeName[playIndex],playPostion[playIndex]));
whoCan[playIndex]=true;//開啟繼續搖骰子
whoCan[1-playIndex]=false;
ResultTell(string.Format("{0}繼續投擲。",playeName[playIndex]));
break;
case6://大羅移
ResultTell(string.Format("恭喜!{0}踩中大羅移,請選擇是否移動!當前位置是{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];//將此方現在位置賦給記錄上次位置的數組
playStan[1-playIndex]=playPostion[1-playIndex];//將另一方現在的位置賦給記錄上次位置的數組
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
mapImg[road[playPostion[1-playIndex]]].Image=imageList1.Images[1-playIndex];
ResultTell(string.Format("{0}的當前位置是{1},{2}的當前位置是{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步!當前位置是{1}",playeName[playIndex],playPostion[playIndex]));
DialogResultdrr=MessageBox.Show("是否選擇擊退對方!","手槍!",MessageBoxButtons.YesNo);
if(drr==DialogResult.Yes)
playStan[1-playIndex]=playPostion[1-playIndex];//記錄對方位置
playPostion[1-playIndex]-=3;//對方現在位置后移3個
mapImg[road[playPostion[1-playIndex]]].Image=imageList1.Images[1-playIndex];//添加圖片
ChangImg(1-playIndex);
ResultTell(string.Format("{0}被擊退對方3步!當前位置是{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;
*第二輪結束
whcan[0]=false,whcan[1]=true;
第三輪開始
whcan[0]=false,whcan[1]=true;
//三輪結束
whcan[0]=true,whcan[1]=false;
privatevoidChangImg(intplayIndex)
//如果位置相同換成兩個飛機的圖片
if(playPostion[1]==playPostion[0])
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[2];
else//如果不同則位置對應的圖片
mapImg[road[playPostion[playIndex]]].Image=imageList1.Images[playIndex];
//雙方已經出發,兩個人在同一位置,此方圖片離開后,顯示另一方圖片
if(playStan[0]==playStan[1]playStan[0]!=-1playStan[0]!=-1)//如果上次位置雙方相同
mapImg[road[playStan[playIndex]]].Image=imageList1.Images[1-playIndex];
else//上次雙方位置不同,變為之前默認的圖片
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://結束位置
mapImg[road[playStan[playIndex]]].Image=Image.FromFile("../../img/game-over.jpg");
break;
default:
break;
//判斷投擲完一輪,相同點數,誰點數大誰再投擲
privatevoidOutDoor()
//投擲完一輪,并且雙方都存有點數
if(whoCan[0]!whoCan[1](startNum[0]!=0||startNum[1]!=0))
{//雙方點數相同
if(startNum[0].Equals(startNum[1]))
ResultTell("雙方點數相同,請重新投擲!");
else
start=false;//不是第一回合
if(startNum[0]startNum[1])
ResultTell("紅方點數較大,先行一步,紅方投擲");
whoCan[0]=true;//紅方繼續投擲
whoCan[1]=false;
else
ResultTell("綠方點數較大,先行一步,綠方投擲");
whoCan[0]=false;
whoCan[1]=true;//綠方繼續投擲
voidInitialGame()//初始化地圖
for(inti=0;imapImg.Length;i++)
CreateMap();//調用存儲數字的圖片
CreateGear();//調用創建機關的方法必須向有路,才能調用機關的方法
PictureBoxpicture=newPictureBox();
picture.Size=newSize(size,size);
mapImg[i]=picture;//圖片添加到數組
switch(mapList[i])//判斷地圖數組中存儲的數字,添加圖片
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://結束位置
picture.Image=Image.FromFile("../../img/game-over.jpg");
break;
default:
break;
picture.SizeMode=PictureBoxSizeMode.StretchImage;//圖片適應大小
picture.Location=newPoint(i%30*size,i/30*size);
map.Controls.Add(picture);//圖片添加到地圖中
voidCreateMap()//創建地圖
CreateRoed();//創建路
for(inti=0;iroad.Length;i++)
mapList[road[i]]=1;//路將路對應的索引變為1
mapList[0]=10;//開始位置
mapList[
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 基于深度學習的過濾水質預測研究
- 沉浸式教學法在初級漢語綜合課的應用行動研究-以泰國岱密中學為例
- 胎盤影像診斷
- 感統組合培訓
- 集中注意力與心理健康維護
- 闌尾手術護理查房
- 《智能網聯汽車技術》課件-超聲波雷達
- 預防溺水班會課件
- 頂崗實習安全課件
- 音標課件圖片高清
- 心臟驟停后高質量目標溫度管理專家共識2024
- 合同債權轉讓及違約金協議
- 售后服務電話回訪管理辦法
- 《中國糖尿病防治指南(2024版)》更新解讀
- 2025年休克治療指南:課件解讀與實踐
- 浙江省臺州市溫嶺市2023-2024學年五年級上學期英語期末試卷
- 水穩質量保證措施
- 醫療器械自研軟件研究報告
- 《高性能計算 分布式存儲系統技術要求》
- 市場總監聘用合同模板
- 個人租車合同范本
評論
0/150
提交評論