我需要幫助我爲java分配任務。任務是:捕獲兩者之間的顏色?
創建一個遊戲,其中: 有兩個棋子,黑色和白色的。 當一塊或一行棋子在其左右兩側或前後都被對手包圍時,據說它被捕獲,並且其顏色會變爲包圍它的棋子的顏色。輪到你時,你必須至少抓住一個對手的棋子。 當用戶沒有更有效的移動時,遊戲結束。 獲勝者被分配給獲得更多作品的玩家。
董事會是6x6,你只需要用文字顯示結果,而不是實際的遊戲。我只知道如何使用數組創建一個電路板。我不知道如何編碼實際的遊戲。一些幫助將非常感謝!我知道我必須使用很多「if」語句和循環,但我不知道該怎麼做。這是我到目前爲止:
boardA[0] = "A1";
boardA[1] = "A2";
boardA[2] = "A3";
boardA[3] = "A4";
boardA[4] = "A5";
boardA[5] = "A6";
boardB[0] = "B1";
boardB[1] = "B2";
boardB[2] = "B3";
boardB[3] = "B4";
boardB[4] = "B5";
boardB[5] = "B6";
boardC[0] = "C1";
boardC[1] = "C2";
boardC[2] = "C3";
boardC[3] = "C4";
boardC[4] = "C5";
boardC[5] = "C6";
boardD[0] = "D1";
boardD[1] = "D2";
boardD[2] = "D3";
boardD[3] = "D4";
boardD[4] = "D5";
boardD[5] = "D6";
boardE[0] = "E1";
boardE[1] = "E2";
boardE[2] = "E3";
boardE[3] = "E4";
boardE[4] = "E5";
boardE[5] = "E6";
boardF[0] = "F1";
boardF[1] = "F2";
boardF[2] = "F3";
boardF[3] = "F4";
boardF[4] = "F5";
boardF[5] = "F6";
Scanner keyboard = new Scanner(System.in);
System.out.println("This is how the board looks like:" + "\n" + Arrays.toString(boardA) +
"\n" + Arrays.toString(boardB)+ "\n" + Arrays.toString(boardC)
+"\n"+ Arrays.toString(boardD) +"\n"+Arrays.toString(boardE)
+ "\n"+Arrays.toString(boardF));
System.out.println("The board has 6 blocks, starting with 4 people in the middle, 2 black and 2 white facing each other.");
boardC[2] = "white";
boardC[3] = "black";
boardD[2] = "black";
boardD[3] = "white";
System.out.println("The board starts with: " + "\n" + Arrays.toString(boardA) +
"\n" + Arrays.toString(boardB)+ "\n" + Arrays.toString(boardC)
+"\n"+ Arrays.toString(boardD) +"\n"+Arrays.toString(boardE)
+ "\n"+Arrays.toString(boardF));
System.out.println("You are white. Where do you want to move?");
String input = keyboard.nextLine();
這不是很多,不像這裏介紹的那樣編譯。那麼你究竟是從寫下一個數組開始嘗試呢?你的具體問題在哪裏?我們不會爲你完成你的任務,但是如果你提出更精確的問題,我們可以幫助你:「如何完成這項任務?」。嘗試考慮一個循環,其中包含遊戲結束時的條件和每個回合允許的動作及其結果。嘗試編寫一些關於該代碼的代碼,然後與我們分享,以便我們更好地瞭解您的問題。我敢打賭,你有關於如何從你的課程中解決它的信息。 –
我真的不知道。我的教授只是把它扔給我們,卻沒有向我們顯示任何方向。我們所做的最後一件事情就是創建對象,並搞亂do-while循環。我只想問一問,如何讓程序知道是否包圍了顏色開關。我是否使用if-else語句來記錄每一個可能的移動,還是有更好的方法來做到這一點? – Ccyan