C 飛行棋超全總結(全注釋版)

2021-10-07 07:37:33 字數 4218 閱讀 9477

目錄

1.首先了解c#飛行棋的基本功能

2.實現飛行棋需要哪些準備

3.顯示遊戲頭的showui()方法

4.畫標識和玩家的drawstringmap()方法

5.讀取使用者輸入值的readint()方法

6.擲骰子的rowtouzi()方法

7.初始化地圖的initmap()方法

8.畫地圖上橫行的方法drawstringmaplefttoright()

9.畫地圖的drawmap()方法

10.表示勝利的win()方法

方法名引數返回值型別

作用showui()無無

顯示遊戲頭

drawstringmap()

posstring

畫標識和玩家

readint()

msg,min,max

int讀取使用者輸入的值

rowtouzi()

playerpos

無擲骰子

intmap()無無

初始化地圖

drawstringmaplefttoright()

left,right

無畫地圖橫行

drawmap()無無

畫地圖win()無無

提示使用者勝利

public static void showui()//顯示遊戲頭

public static string drawstringmap(int pos)//定義乙個畫地圖的方法

else if (playerpos[0] == pos )//如果玩家a在地圖上就畫a

else if (playerpos[1] == pos )//如果玩家b在地圖上就畫b

else

// end switch

}// end if

return temp;//返回temp的值

}

public static int readint(string msg,int min,int max)//定義乙個方法,讀取使用者輸入的值

else//證明number的值沒有在min和max之間

到之間的數字!", min, max);//輸出提示

continue;}}

catch//如果強制轉換發生異常,進入catch語句

}}

public static void rowtouzi(int playerpos)//定義乙個擲骰子的方法,有乙個整型引數playpos,無返回值

按任意鍵開始擲骰子", playernames[playerpos]);//輸出某玩家的姓名按任意鍵開始擲骰子

console.readkey(true);//當玩家按下任意鍵後繼續

console.writeline("擲出了", playernames[playerpos],num);//輸出提示玩家誰誰誰擲出了某個數字

console.writeline("按任意鍵開始行動......", playernames[playerpos ]);//輸出提示誰誰誰可以按任意鍵開始行動

console.readkey(true);//當玩家按下任意鍵後繼續

playerpos[playerpos] += num;//上述玩家的新位置值等於原位置加上num的值,即擲出來的值

checkpos();//呼叫checkpos()方法,確保玩家位置還在地圖上

if (playerpos[playerpos]==playerpos[1-playerpos ])//判斷玩家移動後的位置是否與另一位玩家位置相同,若相同,則繼續

踩到了玩家,玩家退6格", playernames[playerpos], playernames[1 - playerpos], playernames[1 - playerpos]);//走到這裡,證明兩個玩家位置相同,即符合踩一腳規則,將字串"玩家某踩到了玩家某,玩家某退6格"這個字串賦給msg

playerpos[1 - playerpos] -= 6;//被踩玩家的位置值-6

checkpos();//呼叫checkpos()方法,確保被踩玩家位置還在地圖上

}else//玩家移動後位置與另一位玩家位置不同,遊戲繼續

走到了幸運輪盤,請選擇1——交換位置,2——轟炸對方", playernames[playerpos]);//輸出提示

int number = readint(msg, 1, 2);//呼叫readint方法,讀取使用者輸入的值,並定義乙個整型變數number來接受該方法的返回值

if (number == 1)//如果返回值為1

選擇了與玩家交換位置", playernames[playerpos], playernames[1 - playerpos]);//輸出提示

}else//返回值不為1,即代表當前玩家選擇了轟炸對方

選擇轟炸玩家", playernames[playerpos], playernames[1 - playerpos]);//輸出提示

}break;//跳出switch

case 2://索引值為2,代表玩家處於地雷位置

msg = "恭喜你,能踩到地雷,百年不遇,退6格";//輸出提示

playerpos[playerpos] -= 6;//當前玩家位置-6

checkpos();//呼叫checkpos()方法,確保被踩玩家位置還在地圖上

break;//跳出switch

case 3://索引值為3,代表玩家處於暫停位置

msg = "踩到暫停了";//輸出提示

flag[playerpos] = true;//該玩家暫停狀態的值變為true,代表處於暫停狀態

break;//跳出switch

case 4://索引值為4,代表玩家處於時空隧道位置

msg="恭喜你,這個猥瑣傢伙居然穿越了10步";//輸出提示

playerpos[playerpos] += 10;//當前玩家位置+10

checkpos();// 呼叫checkpos()方法,確保被踩玩家位置還在地圖上

break;//跳出switch}}

console.clear();//清除螢幕

drawmap();//呼叫畫地圖方法

console.writeline(msg);//輸出提示

}

public static void initmap()//定義乙個方法初始化地圖

;//定義幸運輪盤陣列並賦初值,代表地圖上幸運輪盤所處的位置

int landmine = ;//定義地雷陣列並賦初值,代表地圖上地雷所處的位置

int pause = ;//定義暫停陣列並賦初值,代表地圖上暫停所處的位置

int timetunnel = ;//定義時空隧道陣列並賦初值,代表地圖上時空隧道所處的位置

for (int i = 0; i < luckturn.length; i++)

for (int i = 0; i < landmine.length; i++)

for (int i = 0; i < pause.length; i++)

for (int i = 0; i < timetunnel.length; i++)

}

public static void drawstringmaplefttoright(int left, int right)//定義乙個畫橫行的方法,有兩個整型引數,left和right

}

public static void drawmap()//定義畫地圖的方法

console.writeline(drawstringmap(i));//呼叫畫地圖的方法,並在螢幕上輸出

}//畫地圖第二橫行

for (int i=64;i>=35;i--)

console.writeline();//換行繼續畫

//畫第二豎行

for (int i=65;i<=69;i++)

drawstringmaplefttoright(70, 99);//呼叫畫橫行的方法畫第三橫行,引數為70和99

console.writeline();//輸出在螢幕上

}

public static void win()//定義乙個勝利的方法,用來在玩家勝利時提示勝利介面

飛行棋總結

方法名 引數返回值 功能showui無無 顯示遊戲表頭 initmap無無 將放置障礙的位置用數字列出,然後將顯示同一種障礙位置的陣列進行在賦值,1 為一種障礙 2 為一種障礙 3 為一種障礙 等等 drawmap無無 畫地圖 橫行,豎行 drawstringmap int pos string 畫...

C 飛行棋遊戲

1 using system 2using system.collections.generic 3using system.linq 4using system.text 5using system.threading.tasks 67 namespace 05.飛行棋遊戲834 35 conso...

騎士飛行棋專案總結

今年元旦,做了傳智播客的騎士飛行棋專案,是個c 控制台程式。我是初學者,還不了解uml,沒有什麼建模,邏輯圖之類的思路。不過做完了之後,還真是覺得對於我這個初學者的鍛鍊很大。1.把需求用方法來分解,重要的一條就是如果出現大量重複的 就應該可以寫成乙個方法 2.在設計的時候對於變數的定義,比如如果能定...