Sign in to follow this  
Tristan85

[MVC] Visualizing controls

Recommended Posts

Hi everyone, For a chess game I'm creating as an example for my students I am currently using the MVC pattern. There is a BoardModel, a BoardView and a BoardController class. Currently the BoardController class depends on BoardView and BoardModel. BoardView depends on BoardModel. BoardModel is not dependant on BoardView or BoardController. BoardController delegates control of the board to one of two Player classes, depending on whose turn it is. The HumanPlayer class (subclass of Player) allows the player to first select a square of the board with a piece, and then select another square on the board to move that piece to. Here's where trouble begins: I want to provide some visual feedback of which squares the user is selecting. But this would either create a dependency of BoardView on HumanPlayer (part of the controller layer), or add the notion of which squares are selected to the BoardView class...but this notion is typical for the way a HumanPlayer controls the board since an AIPlayer just performs the move instantly. Summarizing: a certain type of control-mechanism (so not part of the model) should be visualized to the user. How would you guys handle such a case? Kind regards, Tristan

Share this post


Link to post
Share on other sites
Interesting problem. A lot of people are moving to MVC-based systems for games recently, at least on these forums, and it's the corner cases like these that trip people up.

Perhaps the problem is that it's too restrictive to think of it only in terms of the Board. A player's current selection is not an intrinsic part of the board as such, but is part of the game. So one way to think about it is for your View (in the abstract sense) to be composed of a BoardView and a GameView. The GameView would obtain its data from the GameModel (eg. Game::getSelectedSquare as (x,y) ) and has a dependency on BoardView as to how to present that (or vice versa - it doesn't really matter, as the key thing is that the views only depend on views or model, not on the controller), and the HumanPlayer can call Game::setSelectedSquare to tell the model which square it's working with. The AIPlayer by comparison could call the method with a null parameter or something similar to turn the feature off, and the GameView would pick this up accordingly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this