Game Screens
Author |
Message |
evogre3n
|
Posted: Mon Dec 26, 2005 9:09 pm Post subject: Game Screens |
|
|
My upcoming game (Battleship) will be my first game using SWING and such.
I am wondering how to create multiple screens...
I will have 3 screens..
intro screen
main menu screen --> game screens ---> --- back to main menu
exit screen
And I was thinking of coding each screen in a seperate class, so I will have my main game class, and 3 other classes that will be initialized:
code: | Intro intro = new Intro ();
MainMenu mainmenu = new MainMenu ();
GoodBye goodbye = new GoodBye ();
|
Now, I have to display each screen and I was thinking of doing it something like this: (in the main program after initializing the screen objects (which extends JPanel))
code: | while (true) {
this.add (intro);
if (intro.getPanelStatus == PANEL.OFF) {
this.remove (intro);
this.add (mainmenu);
if (mainmenu.getPanelStatus == PANEL.OFF) {
this.remove (mainmenu);
break;
}
}
}
|
Each screen, (class) will extend JPanel and implement ActionListener, all will contain a field:
code: | private panelStatus;
|
which will have one of 2 values
code: | public final int PANEL.OFF = 0;
public final int PANEL.ON = 1;
|
and all will have the accessor
code: | public int getPanelStatus () {
return this.panelStatus ();
}
|
and finally, all will contain a mutator
code: | public void setPanelStatus (int status) {
this.panelStatus = status;
}
|
The mutator for the status will be invoked by the ActionListener.. so when they press "Click to continue" within the intro screen, it will invoke setPanelStatus of intro etc.
My question is, am I going about this the right way... or is this overly complicated and there is a simpler way to do it?
Thanks a lot |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
evogre3n
|
Posted: Tue Dec 27, 2005 10:40 am Post subject: (No subject) |
|
|
Update: this method doesnt work... i need the main program to constantly check for statechange...
I guess that means this is not the right way to go about it..
Anyone have suggestions?
Thanks |
|
|
|
|
 |
|
|