我必须为我的大学里的一门实用课程设计一个reversi版本。它应该具有单人模式(对抗自己编写的人工智能),热座模式和通过互联网的多人模式。到目前为止,我已经用MVC编写了reversi的类,对于这些类,我使用了以下三个接口。( Board-Class模拟具有操纵方法的电路板。)但现在我想知道我应该如何实现这三个基本功能。我的第一个想法是实现第二层MVC ( Hotseat,AI和Network各一层),在那里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();}
发布于 2012-12-17 20:17:03
由于这是一项大学任务,我不想详细说明答案。
我会在游戏和第二个玩家之间创建一种“协议”。因为玩家动作显然是与控制器相关的,所以我会实例化不同的第二玩家类,它们要么直接响应移动(=AI),要么等待一些输入(无论是通过接口还是互联网)。
这与策略模式非常接近。
https://stackoverflow.com/questions/13803729
复制相似问题