• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where to store the game state.

 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like it would be part of the control mechanism, along with listeners etc
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it depends on how your game is structured,
if it is MVC then in the model

if it is split into 2
1) listeners,game logic
2) gui
then with the listeners/game logic.

 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it really matter if the listeners are added in the view code or the controller code eg in the constructor of the JPanel to have

or is it better to pass the JPanel reference to the controller and add the listnerers there.
Keeing the view code strictly for updating the UI.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timmy Ryan wrote:Does it really matter if the listeners are added in the view code or the controller code eg in the constructor of the JPanel to have

or is it better to pass the JPanel reference to the controller and add the listnerers there.
Keeing the view code strictly for updating the UI.


The bit in bold is the official line, but i never really achieved it, so will pass the baton along
 
Timmy Ryan
Ranch Hand
Posts: 63
IntelliJ IDE Java Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic