I have a board game in which a human can play against the computer.
The details about an on-going human v computer game are stored in a Game class.
My problem is that I dont know where is the correct place to store this game object should be, which must persist between human moves.
As the view should know nothing about the model or the controller.
When a human takes there move I have to pass the start and end squares of the move to some class that will validate the move.
Maybe I didnt explain the situation in the original post great.
In the Jpanel which recieves the users moves it needs to call another class to verify the users move and to calculate the computers response.
Today this it needs a copy of the game state object, but where should this game object be stored.
In the Jpanel class that controls the user interface? Does this not mean that the UI knows about the game when it should not.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
sounds like it would be part of the control mechanism, along with listeners etc
I have carried out a bit of refactoring on the project.
The controller will create the view through composition.
Currently I have a number of sub panels in the view and these are implemented as singletons.
So when one panel wanted to change the appearance of a component on another panel they would call.
from within its own panel.
Q1. Should each panel be a singleton, I am thinking not.
Q1a. If one component wants to change another should this done through the controller?
In the view there are JSplitPane which contain JSplitPane and so on.
Q2. In the top level view creation class GameView should I have a reference to all of these sub components, e.g
GameView contains all the sub containers and components,
Q3. In the code below should I have the addMouseListener for a panel.