Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Restart question...  (Read 1246 times)
0 Members and 1 Guest are viewing this topic.
Offline Baan

Junior Newbie




Java games rock!


« Posted 2005-05-20 14:34:40 »

Hi guys. Me and a few friend are working on a racing game in 2D as a project for school. Most of it is done and good to go, but we have one remaining (bigger) problem which we haven't been able to solve yet.

First the game is basically a menu, and when you've set up the type of game etc you get to the racing itself which is basically the second part of the program. Also the frame which the game is shown in is sent to the class that controlls the actual game classes. So the problem is, when one player has finished the race (it's a two player game) we're supposed to get back  to main menu.

No one really has an idea how to do this, we were thinking about "starting over" when the race is finished but even so, no idea how to do that. So does anyone have any suggestions how to basically restart the whole menu then playing procedure?
Offline Raghar

Junior Devvie




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #1 - Posted 2005-05-20 16:02:46 »

yes

menu = new RaceMenu();

And the second thing to do is move it to newbies clubies.
Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #2 - Posted 2005-05-20 16:31:32 »

If you've written the game, then this really ought to be easy, although your code will need a restructure.

You need to split your initialisation code into two halves.
1) Stuff that only needs to be initialised once
2) Stuff that needs to be reset every game.

You can leave 1) in the constructor of the classes & put 2) in a separate method, e.g. public void reset().  You can put a call into reset() at the end of the constructor if needs be.

If a class contains references of other classes (e.g. if you have a Car class which contains references to four Wheel classes), you need to make sure that your (Car) reset() method calls the reset() method on those other (Wheel) classes.  That way when you call reset() on the top level class, all the others get reset too.

If the Menu system is AWT or Swing and needs to be hidden when playing the game and then recreated, you can add member functions to your main class to do the job & call them from your game loop. You will also need to call CreateMenu from the constructor

Now you can structure your main loop long the lines of:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public void playGameOnce() {
  destroyMenu();
  reset();
  while (!gameOver) {
    movement();
    ai();
    render();
   }
   createMenu();
 }


Time flies like a bird. Fruit flies like a banana.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Baan

Junior Newbie




Java games rock!


« Reply #3 - Posted 2005-05-20 16:37:38 »

Quote
yes

menu = new RaceMenu();

And the second thing to do is move it to newbies clubies.


yeah thanks alot I've always been curios about how to create new object references! *sarcasm*

-----------------

Alan_W

thanks for the advice, we've been doing something like that already, but I'll try it out! Only problem is we're on a deadline now so it's a bit stressful atm
Offline Raghar

Junior Devvie




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #4 - Posted 2005-05-21 13:01:05 »

You are wellcomed. I think you should review what I said and Alan extended to easily understable form.
And if you have problems even now, you should look at a final state machine.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2005-05-22 12:48:08 »

Quote
You are wellcomed. I think you should review what I said and Alan extended to easily understable form.
And if you have problems even now, you should look at a final state machine.

Uh, finite state machine, surely?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Raghar

Junior Devvie




Ue ni taete 'ru hitomi ni kono mi wa dou utsuru


« Reply #6 - Posted 2005-05-23 23:49:10 »

Or FSM, or FSA. It has a lot of names.
Or are you trying to imply that your implementation of FSM didn't entered a final state thus running in a tight loop and making the computer unresponsive? ~_^

I should however take care to don't use that terms from Game dev forums...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!