This section illustrates the mappings among Views, Models, and States.
Mapping in a Game class
A subclass of the Game class possesses Views, Models, and States. It also maps these classes. The following code in the game template shows how these classes are mapped in the class.
class NewGame < Game
def initialize()
@bindings = [[NewGamePlayingState, NewGameModel, NewGameView]]
@initialState = NewGamePlayingState
end
def self.title() "NewGame" end
def self.titleImage() nil end
end
The instance variable @bindings has a double Array object. Each content of the Array object contains a State class, a Model class, and a View class in this order. When a game is selected at the main title, the framework sets a Model object to both a View object and a State object. For example, both an object of NewGameState and an object of NewGameView have an instance variable @model that represents an objects of NewGameModel.
Mappings for a game that has multiple states
If there are more than one State classes that are related to the same pair of a Model object and a View object, @binding would be as follows:
@bindings = [[FirstState, MyGameModel, MyGameView],
[SecondState, MyGameModel, MyGameView],
[ThirdState, MyGameModel, MyGameView]]
The framework will create a MyGameModel object, a MyGameView object, and three State objects. It, then, maps each State object to the MyGameModel. It also maps the MyGameView objects to the MyGameModel object. As a result, each @model in the subclasses of State has the MyGameModel object. The @model in the MyGameView object is also set to the MyGameModel.







