【问题标题】:Reversi Software Design黑白棋软件设计
【发布时间】:2012-11-28 00:43:46
【问题描述】:

我必须为我大学的一门实践课程设计一个黑白棋版本。它应该具有单人模式(针对自写的 AI)、热座模式和通过互联网的多人模式。 到目前为止,我已经在 MVC 中编写了黑白棋类,为此我使用了以下三个接口。 (Board-Class 模拟了一个具有操作它的方法的板。) 但是现在我想知道我应该如何实现这三个基本功能。我的第一个想法是实现 MVC 的第二层(Hotseat、AI 和网络各一个),其中 reversiController 将用户所做的所有输入传输到上层,上层决定如何处理这个动作。上层的移动应该将下层的视图作为一个框架,并为用户显示额外的信息和可能性(同样,取决于游戏的类型) 这是一个合理的方法,或者你将如何处理这个问题? 提前致谢!

public interface IGame {
void addObserver(Observer obs);
Cell getCell(int i, int j);
Cell getWinner();
List<Move> generateMoves(Cell player); 
void move(Move move);
Cell getNextPlayer();
boolean hasEnded();
void reset();
boolean isLegalMove(Move move);
Board getBoard();

}

public interface IReversiView {

/**
 * Show Reversi UI
 */
void showReversi();

}

公共接口 IReversiController {

/**
 * Sets the game's view.
 * 
 * @param view
 */
void setView(IReversiView view);

/**
 * Shows the user interface.
 */
void start();

/**
 * 
 * Handles a move called by the user and transmits it to the model.
 * 
 * @param x
 * @param y
 */
void handleMove(Move move);

/**
 * Resets the game to default state.
 */
void resetGame();

}

【问题讨论】:

    标签: java design-patterns reversi


    【解决方案1】:

    由于这是大学任务,我不想详细说明答案。

    我会在游戏和第二个玩家之间创建一种“协议”。由于玩家动作显然与控制器相关,因此我将实例化不同的第二玩家类,它们要么直接响应移动 (=AI),要么等待某些输入(通过界面或互联网)。

    这与策略模式相当接近。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      • 2013-06-18
      相关资源
      最近更新 更多