Skip to main content
gamedev.net
🔒 Locked

[MVC] Visualizing controls

Started by Tristan85 May 29, 2009 at 4:11 AM 0 replies 500+ views
Original Post
Tristan85
Tristan85
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
Kylotan
Kylotan
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.