Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  How would I restart a class?  (Read 1275 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Posted 2004-01-09 09:38:03 »

I'm finished my noughts and crosses game, almost. I gave the option to restart or quite the game after the game ends.

How would I restart my game?
I tried restarting the applet (it's in a JFrame) by calling destroy and then init method.
Doesn't work.

Any ideas?

Thanks

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
pokkelipoo
Guest
« Reply #1 - Posted 2004-01-09 13:23:17 »

Separate your frame/applet code and game code clearly. So when restarting, just re-create or reset the game stuff.
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #2 - Posted 2004-01-09 21:32:57 »

Exactly.
Try to think of what the Applet actually *is*: An online application embedded in a web page, nothing more, nothing less.
You don't want to restart the Applet, you want to restart your *game*, not the whole applet. Try to refactor your code, so you can simply call Game.start() or something and that your class extending Applet will be dumb enough to just show what your 'Game' class does without knowing much else.
A (shaky) analogy: When you start an application on your PC, you're not restarting your whole PC, are you?

(meant as constructive criticism  Smiley)

Erik

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #3 - Posted 2004-01-09 21:51:27 »

Thanks, I think I know where you guys are going with this. Smiley

I do have my class constructor, I use that to start my program.
I need a stop method that will act as a destructor.
I will experiment with this.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Jeff

JGO Coder




Got any cats?


« Reply #4 - Posted 2004-01-13 23:27:01 »

Your starting object that is called  by the applet is like any other object.  If you return out of it and there are no other references it becomes a candidate for collection.

Not that you really should care, all you should really need to do is return any resources it grabbed and exit abck to your launch code.

This can be complciated IF you are using static varibales anywhere.  These will need to be set back to their initial states by your code.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
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.

TehJavaDev (15 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (34 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (30 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (43 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!