久草成人在线视频,欧美激情视频网,级别免费毛片在线看,中文字幕色婷婷在线视频,亚洲天堂成人在线,久久亚洲婷,日本黄色网址在线免费

java騎士飛行棋

上傳人:go****ng 文檔編號:142143083 上傳時間:2022-08-24 格式:DOC 頁數(shù):14 大?。?9KB
收藏 版權(quán)申訴 舉報 下載
java騎士飛行棋_第1頁
第1頁 / 共14頁
java騎士飛行棋_第2頁
第2頁 / 共14頁
java騎士飛行棋_第3頁
第3頁 / 共14頁

下載文檔到電腦,查找使用更方便

9.9 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《java騎士飛行棋》由會員分享,可在線閱讀,更多相關(guān)《java騎士飛行棋(14頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、騎士飛行棋 騎士飛行棋簡介: 《騎士飛行棋》又名《別生氣》,是一款跟傳統(tǒng)的飛行棋一模一樣的小游戲。游戲中每家有4個棋兵,誰4個兵最先到達(dá)目的地誰就贏(每一家的目的地各不相同,用顏色區(qū)別,大本營是什么顏色目的就是什么顏色)。當(dāng)沒有活動的兵時,每家可以連續(xù)扔3次,直到扔出6點釋放出一個兵。之后每輪只能扔一次,棋兵前進(jìn)的格數(shù)由扔出的點數(shù)決定,扔幾點就走幾步。無論是前進(jìn)或者后退,當(dāng)棋兵最后落腳的地方踩到對方棋兵時,就把對方棋兵轟回老家,當(dāng)踩到地雷就后退6格,當(dāng)踩到“¤”時,就進(jìn)入幸運輪盤,里面有8種運氣:前進(jìn)、后退、交換位置、轉(zhuǎn)移、暫停一輪、獎勵一次、設(shè)置地雷、轟炸(將對方棋兵炸退6步)。 一、

2、需求分析: 1、定義一個類MAP,生成游戲中的地圖,地圖中包括幸運輪盤“¤”的位置,地雷位置,暫停位置,時候隧道位置。同時構(gòu)造成員方法creatMap生成對戰(zhàn)圖,設(shè)置相關(guān)的成員變量;構(gòu)造成員方法getGraph返回地圖當(dāng)前位置的對應(yīng)圖片。定義構(gòu)造方法showLine1輸出地圖的奇數(shù)行(第1、3行),定義showLine2輸出地圖的偶數(shù)行(第2行);定義showRLine輸出地圖的右豎列;定義showLLine輸出地圖的左數(shù)列;最后定義showMap方法顯示對戰(zhàn)圖。 2、定義游戲類Game,定義相關(guān)的成員變量,包括對戰(zhàn)圖map,對戰(zhàn)中玩家1的當(dāng)前位置playerPos1,對戰(zhàn)中玩家2的當(dāng)前位

3、置playerPos2,走或停標(biāo)識設(shè)置goAndStop,對戰(zhàn)角色playerName。構(gòu)造成員方法init()調(diào)用生成地圖方法creatMap;開始游戲方法start(),同時構(gòu)造成員方法setRole設(shè)置對戰(zhàn)角色。構(gòu)造對戰(zhàn)玩法的方法play。其中方法play中調(diào)用擲骰子成員方法throwShifter,并返回擲出的骰子數(shù)目;構(gòu)造成員方法getCurPos計算玩家此次移動后的當(dāng)前位置,返回移動后的位置,構(gòu)造方法judge 顯示對戰(zhàn)結(jié)果。 3、定義類StartGame啟動游戲。 4、本程序是兩人對戰(zhàn)玩法。 5、程序執(zhí)行的命令:1)啟動游戲 2)創(chuàng)建游戲類Game 3)開始游戲 4)定義

4、測試類。 二、概要設(shè)計: 1、定義啟動游戲類StartGame: //啟動游戲 class StartGame { public static void main(String[] args) { Game game = new Game(); //創(chuàng)建游戲類 game.start(); //開始游戲 } } 2、創(chuàng)建游戲類Game: public class Game { Map map; //地圖 int playerPos1; //對戰(zhàn)中玩家1的當(dāng)前位置

5、 int playerPos2; //對戰(zhàn)中玩家2的當(dāng)前位置 String[] goAndStop = new String[2]; //走或停標(biāo)識設(shè)置 String[] playerName = new String[2]; //對戰(zhàn)角色 public void init(){ //調(diào)用createMap()生成地圖 } public void start(){ //兩人對戰(zhàn)開始游戲 } public void setRole(int no, int role){ //設(shè)置對戰(zhàn)角色 } public void play(){ //兩人對戰(zhàn)玩法 }

6、 public int throwShifter(int no){ //擲骰子并返回擲出的骰子數(shù)目 } public int getCurPos(int no, int position, int step){ //計算玩家此次移動后的當(dāng)前位置并返回移動后的位置 } public void judge(){ //顯示對戰(zhàn)結(jié)果 } } 3、定義Map類: class Map { int[] map = new int[100]; //對戰(zhàn)地圖 int[] luckyTurn = {6, 23, 40, 55, 69, 83}; //幸運輪盤

7、 int[] landMine = {5, 13, 17, 33, 38, 50, 64, 80, 94}; //地雷位置 int[] pause = {9, 27, 60, 93}; //暫停 int[] timeTunnel = {20, 25, 45, 63, 72, 88, 90}; //時空隧道 public void createMap(){ //生成地圖 } public String getGraph(int i, int index, int playerPos1, int playerPos2){ //顯示地圖關(guān)卡

8、對應(yīng)的圖形并返回地圖當(dāng)前位置的對應(yīng)圖片 } public void showLine1(int start, int end, int playerPos1, int playerPos2){ //輸出地圖的奇數(shù)行(第1、3行) } public void showLine2(int start, int end, int playerPos1, int playerPos2){ //輸出地圖的偶數(shù)行(第2行) } public void showRLine(int start, int end, int playerPos1, int playerPos2){ /輸出地圖的

9、右豎列 } public void showLLine(int start, int end, int playerPos1, int playerPos2) { //輸出地圖的左豎列 } public void showMap(int playerPos1, int playerPos2){ //顯示對戰(zhàn)地圖 } } 4、定義測試類Test: class Test { public static void main(String[] args) { Map map = new Map(); map.createMap();

10、 map.showMap(0, 0); } } 三、程序代碼: import java.util.*; //Map類 public class Game { Map map; //地圖 int playerPos1; //對戰(zhàn)中玩家1的當(dāng)前位置 int playerPos2; //對戰(zhàn)中玩家2的當(dāng)前位置 String[] goAndStop = new String[2]; //走或停標(biāo)識設(shè)置 String[] playerName = new String[2]; //對戰(zhàn)角色

11、 // 初始化游戲的一局 public void init() { map = new Map(); map.createMap(); //生成地圖 playerPos1 = 0; //設(shè)置玩家1起始位置 playerPos2 = 0; //設(shè)置玩家2起始位置 goAndStop[0] = "on"; //記錄玩家1下一次走或停 goAndStop[1] = "on"; //設(shè)置玩家2下一次走或停 } //開始游戲 public void

12、 start() { //初始化 init(); System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※"); System.out.println("http:// //"); System.out.println("http:// //"); System.out.pr

13、intln("http:// 騎 士 飛 行 棋 //"); System.out.println("http:// //"); System.out.println("http:// //"); System.out.println("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n\

14、n"); System.out.println("\n~~~~~~~~~~~~~~~~~~~兩 人 對 戰(zhàn)~~~~~~~~~~~~~~~~~~~"); System.out.println("\n請選擇角色: 1. 戴高樂 2. 艾森豪威爾 3. 麥克阿瑟 4. 巴頓"); Scanner input = new Scanner(System.in); System.out.print("請玩家1選擇角色: "); int role1 = input.nextInt(); int

15、 role2; do { System.out.print("請玩家2選擇角色: "); role2 = input.nextInt(); //雙方選擇角色代號 } while (role2 == role1); //不允許角色重復(fù) setRole(1, role1); //設(shè)置玩家1代表的角色 setRole(2, role2); //設(shè)置玩家2代表的角色 play(); //開始兩人對戰(zhàn) } /*設(shè)置對戰(zhàn)角色

16、 *no 玩家次序 1:玩家1 2:玩家2 *role 角色代號 */ public void setRole(int no, int role) { switch (role) { case 1: playerName[no - 1] = "戴高樂"; break; case 2: playerName[no - 1] = "艾森豪威爾"; break;

17、 case 3: playerName[no - 1] = "麥克阿瑟"; break; case 4: playerName[no - 1] = "巴頓"; break; default: break; } } // 兩人對戰(zhàn)玩法 public void play() { Syste

18、m.out.println("\n\n\n\n"); System.out.print("\n\n****************************************************\n"); System.out.print(" Game Start \n"); System.out.print("****************************************************\n\n"); //顯示對戰(zhàn)雙方士兵樣式

19、 System.out.println("^_^" + playerName[0] + "的士兵:?。?); System.out.println("^_^" + playerName[1] + "的士兵: B\n"); //顯示對戰(zhàn)地圖 System.out.println("\n圖例: " + "■ 暫停 ¤ 幸運輪盤 ★ 地雷 〓 時空隧道 ∷ 普通\n"); map.showMap(playerPos1, playerPos2); //游戲開始 i

20、nt step; //存儲骰子數(shù)目 while (playerPos1 < 99 && playerPos2 < 99) { //有任何一方走到終點,跳出循環(huán) //輪流擲骰子 if (goAndStop[0].equals("on")) { //玩家1擲骰子 step = throwShifter(1); //擲骰子 System.out.println("\n-----------------"); //顯示結(jié)

21、果信息 System.out.println("骰子數(shù): " + step); playerPos1 = getCurPos(1, playerPos1, step); //計算這一次移動后的當(dāng)前位置 System.out.println("\n您當(dāng)前位置: " + playerPos1); System.out.println("對方當(dāng)前位置:" + playerPos2); System.out.println("-

22、----------------\n"); map.showMap(playerPos1, playerPos2); //顯示當(dāng)前地圖 if (playerPos1 == 99) { //如果走到終點 break; //退出 } } else { System.out.println("\n" + playerName[0] + "停擲一次!\n"); //顯示此次暫停信息

23、 goAndStop[0] = "on"; //設(shè)置下次可擲狀態(tài) } System.out.println("\n\n\n\n"); if (goAndStop[1].equals("on")) { //玩家2擲骰子 step = throwShifter(2); //擲骰子 System.out.println("\n-----------------"); //顯示結(jié)果信息

24、 System.out.println("骰子數(shù): " + step); playerPos2 = getCurPos(2, playerPos2, step); //計算這一次移動后的當(dāng)前位置 System.out.println("\n您當(dāng)前位置: " + playerPos2); System.out.println("對方當(dāng)前位置:" + playerPos1); System.out.println("----------

25、-------\n"); map.showMap(playerPos1, playerPos2); if (playerPos2 == 99) { //如果走到終點 break; //退出 } } else { System.out.println("\n" + playerName[1] + "停擲一次!\n"); //顯示此次暫停信息 goAndS

26、top[1] = "on"; //設(shè)置下次可擲狀態(tài) } System.out.println("\n\n\n\n"); } //游戲結(jié)束 System.out.println("\n\n\n\n"); System.out.print("****************************************************\n"); System.out.print(" Game Ove

27、r \n"); System.out.print("****************************************************\n\n"); judge(); } /*擲骰子 * no 玩家次序 * return step 擲出的骰子數(shù)目 */ public int throwShifter(int no) { int step = 0; System.out.print("\n\n" +

28、playerName[no - 1] + ", 請您按任意字母鍵后回車啟動擲骰子: "); Scanner input = new Scanner(System.in); String answer = input.next(); step = (int) (Math.random() * 10) % 6 + 1; //產(chǎn)生一個1~6的數(shù)字,即擲的骰子數(shù)目 return step; } /*計算玩家此次移動后的當(dāng)前位置 * no 玩家次序 * position 移動前位置

29、 * step 擲的骰子數(shù)目 * return position 移動后的位置 */ public int getCurPos(int no, int position, int step) { position = position + step; //第一次移動后的位置 if (position >= 99) { return 99; } Scanner input = new Scanner(System.in); switch (m

30、ap.map[position]) { //根據(jù)地圖中的關(guān)卡代號進(jìn)行判斷 case 0: //走到普通格 if (no == 1 && playerPos2 == position) { //玩家1與對方騎兵相遇 playerPos2 = 0; //踩到對方,對方回到起點 System.out.println(":-D 哈哈哈哈...踩到了!"); } if (n

31、o == 2 && playerPos1 == position) { //玩家2與對方騎兵相遇 playerPos1 = 0; //踩到對方,對方回到起點 System.out.println(":-D 哈哈哈哈...踩到了!"); } break; case 1: //幸運輪盤 System.out.println("\n◆◇◆◇◆歡迎進(jìn)入幸運輪盤◆◇◆◇◆");

32、 System.out.println(" 請選擇一種運氣:"); System.out.println(" 1. 交換位置 2. 轟炸"); System.out.println("=============================\n"); int choice = input.nextInt(); int temp; switch (choice) {

33、 case 1: if (no == 1) { temp = position; position = playerPos2; playerPos2 = temp; } else if (no == 2) { temp = position;

34、 position = playerPos1; playerPos1 = temp; } break; case 2: if (no == 1 && playerPos2 < 6) { playerPos2 = 0;

35、 } else { playerPos2 = playerPos2 - 6; } if (no == 2 && playerPos2 < 6) { playerPos1 = 0; } else { playerPos1 = playerPos1 - 6

36、; } break; } //System.out.println(":~) " + "幸福的我都要哭了..."); break; case 2: //踩到地雷 position = position - 6; //踩到地雷退6步 System.out.println("~:-( " + "踩到

37、地雷,氣死了..."); break; case 3: //下一次暫停一次 goAndStop[no - 1] = "off"; //設(shè)置下次暫停擲骰子 System.out.println("~~>_<~~ 要停戰(zhàn)一局了。"); break; case 4: //時空隧道 position = position + 10; //進(jìn)入時空隧道,加走10步

38、 System.out.println("|-P " + "進(jìn)入時空隧道, 真爽!"); break; } //返回此次擲骰子后玩家的位置坐標(biāo) if (position < 0) { return 0; } else if (position > 99) { return 99; } else { return position; } }

39、 //顯示對戰(zhàn)結(jié)果 public void judge() { if (playerPos1 > playerPos2) { System.out.println("\n恭喜" + playerName[0] + "將軍! 您獲勝了!"); } else { System.out.println("\n恭喜" + playerName[1] + "將軍! 您獲勝了!"); } } } //package s1java.xmal1; class M

40、ap { int[] map = new int[100]; //對戰(zhàn)地圖 int[] luckyTurn = {6, 23, 40, 55, 69, 83}; //幸運輪盤 int[] landMine = {5, 13, 17, 33, 38, 50, 64, 80, 94}; //地雷位置 int[] pause = {9, 27, 60, 93}; //暫停 int[] timeTunnel = {20, 25, 45, 63, 72, 88, 90}; //時空隧道 /*生成地圖:

41、 * 關(guān)卡代號為:1:幸運輪盤 2:地雷 3: 暫停 4:時空隧道 0:普通 */ public void createMap() { int i = 0; //在對戰(zhàn)地圖上設(shè)置幸運輪盤 for (i = 0; i < luckyTurn.length; i++) { map[luckyTurn[i]] = 1; } //在對戰(zhàn)地圖上設(shè)置地雷 for (i = 0; i < landMine.length; i++) {

42、 map[landMine[i]] = 2; } //在對戰(zhàn)地圖上設(shè)置暫停 for (i = 0; i < pause.length; i++) { map[pause[i]] = 3; } //在對戰(zhàn)地圖上設(shè)置時空隧道 for (i = 0; i < timeTunnel.length; i++) { map[timeTunnel[i]] = 4; } } /* 顯

43、示地圖關(guān)卡對應(yīng)的圖形 * i 地圖當(dāng)前位置的關(guān)卡代號 * index 當(dāng)前地圖位置編號 * playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 * return 地圖當(dāng)前位置的對應(yīng)圖片 */ public String getGraph(int i, int index, int playerPos1, int playerPos2) { String graph = ""; if (index == playerPos1 && index ==

44、 playerPos2) { graph = "@@"; } else if (index == playerPos1) { //graph = "♀"; graph = "A"; } else if (index == playerPos2) { //graph = "♂"; graph = "B"; } else { switch (i) { cas

45、e 1: //幸運輪盤 graph = "¤"; break; case 2: //地雷 graph = "★"; break; case 3: //暫停 graph = "■"; break; case 4: //時光隧道

46、 graph = "〓"; break; default: graph = "∷"; break; } } return graph; } /** * 輸出地圖的奇數(shù)行(第1、3行) * start 輸出的起始點在地圖上的位置 * end 輸出的結(jié)束點在地圖上的位置

47、* playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 */ public void showLine1(int start, int end, int playerPos1, int playerPos2) { for (int i = start; i < end; i++) { System.out.print(getGraph(map[i], i, playerPos1, playerPos2)); } } /** * 輸出

48、地圖的偶數(shù)行(第2行) * start 輸出的起始點在地圖上的位置 * end 輸出的結(jié)束點在地圖上的位置 * playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 */ public void showLine2(int start, int end, int playerPos1, int playerPos2) { for (int i = end - 1; i >= start; i--) { System.out.print(getGra

49、ph(map[i], i, playerPos1, playerPos2)); } } /** * 輸出地圖的右豎列 * start 輸出的起始點在地圖上的位置 * end 輸出的結(jié)束點在地圖上的位置 * playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 */ public void showRLine(int start, int end, int playerPos1, int playerPos2) { for

50、(int i = start; i < end; i++) { for (int j = 28; j > 0; j--) { //輸出29個空格 System.out.print(" "); } System.out.print(getGraph(map[i], i, playerPos1, playerPos2)); System.out.println(); } } /** * 輸出地圖的左豎列

51、 * start 輸出的起始點在地圖上的位置 * end 輸出的結(jié)束點在地圖上的位置 * playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 */ public void showLLine(int start, int end, int playerPos1, int playerPos2) { for (int i = start; i < end; i++) { System.out.println(getGraph(map[i], i, pl

52、ayerPos1, playerPos2)); } } /** * 顯示對戰(zhàn)地圖 * playerPos1 玩家1的當(dāng)前位置 * playerPos2 玩家2的當(dāng)前位置 */ public void showMap(int playerPos1, int playerPos2) { showLine1(0, 31, playerPos1, playerPos2); //顯示地圖第一行 System.out.println();

53、 //換行 showRLine(31, 35, playerPos1, playerPos2); //顯示地圖右豎行 showLine2(35, 66, playerPos1, playerPos2); //顯示地圖第二行 System.out.println(); //換行 showLLine(66, 69, playerPos1, playerPos2); //顯示地圖左豎行 showLine2(69, 100, playerPos1, player

54、Pos2); //顯示地圖第3行 } } //開始游戲 //package s1java.xmal1; //public class StartGame class StartGame { /** * 啟動游戲 * args */ public static void main(String[] args) { Game game = new Game(); //創(chuàng)建游戲類 game.start(); //開始游戲 } } /

55、/測試類 //package s1java.xmal1; class Test { /* 測試Map類 * args */ public static void main(String[] args) { Map map = new Map(); map.createMap(); map.showMap(0, 0); } } 四、 測試與分析: 1、 調(diào)試中遇到的問題與解決方法: 1) 定義好Map類后不懂怎么解決游戲中前進(jìn)與后退的問題,不知道該怎么寫代碼,經(jīng)上網(wǎng)查詢

56、和查資料解決了。 2) 定義游戲類Game時方法間的調(diào)用出現(xiàn)了問題,思路不清晰,花了大量的時間弄明白方法間的關(guān)聯(lián)問題。 2、 程序改進(jìn)設(shè)想: 界面能不能改成啟動小程序窗口,然后對戰(zhàn)圖在小程序窗口顯示,可樣晚起游戲來界面就能很清晰。 3、 具體調(diào)試過程 游戲開始以及地圖的顯示: 擲骰子后移動相應(yīng)位置后的對戰(zhàn)圖: 五、 試驗體會: 可以說這是第一次接觸飛行棋,以前都沒玩過,為了弄清楚什么是飛行棋,特意的去網(wǎng)上玩了好幾回,也終于弄明白了飛行棋是什么,飛行棋的規(guī)則是什么,對此也有了深入的了解。開始寫代碼的時候,大概知道該定義什么類,但具體寫的時候還是不知道該怎么下手,后來在網(wǎng)上看了幾個相似的代碼后,就有了思路,慢慢的就知道是怎么一回事了,該怎么寫下代碼了。這個實驗讓我們懂得了,只要有耐心,只要肯下功夫,還是有收獲的,并且收獲是你之前無法估量的。

展開閱讀全文
溫馨提示:
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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔

相關(guān)搜索

關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!