快速問題,我開發了3個A.I,每個具有不同的深度。需要幫助爲用戶功能添加難度選項
當前選擇什麼A.I你想對你玩什麼必須進入名爲Main.java的Java文件並將其更改爲你想要的任何一個。要改變的路線是:
chessGame.setPlayer(Piece.COLOR_BLACK, ai3);//Here A.I is assigned
我想允許用戶在遊戲開始時有一個選項來選擇A.I.我希望對界面有所幫助,我在想像一個像JOptionpane這樣的東西可能會起作用。
(我只是不知道如何做一個對A.I選擇)的任何幫助
當前A.I的
AI1 AI2 AI3
package chess;
import chess.ai.SimpleAiPlayerHandler;
import chess.gui.ChessGui;
import chess.logic.ChessGame;
import chess.logic.Piece;
public class Main {
public static void main(String[] args) {
// Creating the Game
ChessGame chessGame = new ChessGame();
// Creating the Human Player
//Human Player is the Object chessGui
ChessGui chessGui = new ChessGui(chessGame);
//Creating the A.I's
SimpleAiPlayerHandler ai1 = new SimpleAiPlayerHandler(chessGame);//Super Dumb
SimpleAiPlayerHandler ai2 = new SimpleAiPlayerHandler(chessGame);//Dumb
SimpleAiPlayerHandler ai3 = new SimpleAiPlayerHandler(chessGame);//Not So Dumb
// Set strength of AI, how far they can see ahead
ai1.maxDepth = 1;
ai1.maxDepth = 2;
ai3.maxDepth = 3;
//Assign the Human to White
chessGame.setPlayer(Piece.COLOR_WHITE, chessGui);
//Assign the not so dumb A.I to black
chessGame.setPlayer(Piece.COLOR_BLACK, ai3);
// in the end we start the game
new Thread(chessGame).start();
}
}
感謝。
你可以使用一個'JComboBox',請參見[如何使用組合框(http://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html)瞭解更多詳情,或您可以在'ButtonGroup'中使用'JRadioButton'或'JToggleButton',參見[如何使用按鈕,複選框和單選按鈕](http://docs.oracle.com/javase/tutorial/uiswing/components/ button.html)以獲取更多詳細信息 – MadProgrammer 2014-11-21 08:44:21
它看起來像您在SimpleAiPlayerHandler中的maxDepth變量是公共的。你應該改變它爲private,並改爲使用一些訪問器或增變器方法。因爲你不太可能在創建對象後改變它,所以你甚至可以把它添加到構造函數中。 – sage88 2014-11-21 08:44:29