3

I have to design a version of reversi for a practical course at my university. It should feature a single player mode (against a self written AI), hotseat mode and multiplayer mode via internet. Until now I have already written the classes for reversi in MVC for which I use the following three interfaces. (The Board-Class simulates a board featuring methods to manipulate it.) But now I wonder how I should implement the three basic features. My first idea was to implement a second layer of MVC (One each for Hotseat,AI and Network), where the reversiController transfers evcery input the user makes to the upper layer which decides what to do with this move. The move of the upper layer is supposed to feature the view of the lower level as a frame and display additional infos and possibilites for the user (again, depending on the type of the game) Is this a reasonable approach, or how would you handle this problem? Thanks in advance!

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();

}

public interface 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();

}

1 Answers1

0

Since this is a university task, I don't want to detail the answers.

I would create sort of a "protocol" between the game and the second player. Since player-actions is clearly something controller-related, I would then instantiate different 2nd-player-classes, which either directly respond with a move (=AI) or wait on some input (be it through the interface or the internet).

This is rather close to the strategy pattern.

SirRichie
  • 1,176
  • 9
  • 14