Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Creating of Thread + splitting game into 2 classes.  (Read 953 times)
0 Members and 1 Guest are viewing this topic.
Offline stef569

Junior Devvie





« Posted 2007-08-31 14:26:15 »

Hi, I've decided that i want to pauze my game and i'll use thread.pauze.
I created it because otherwise all the code will go in the Game class, So I would like to have the Manager 'Manage' the game.
When I say Manage I think of creating stopping pauzing replaying and controlling keybord activity.
The main game loop itself is in Game.
Is this the right way to split the two classes?

This is a code snippet from my Game_Management class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
  private Game game;
  private Thread GameThread;

  /** Creates and Controls a Game */
  Public Game_Management() {
    bFact = new BlockFactory();
    board = new Board(20,10,Block.TILE_SIZE);
    game = new Game(this,board,bFact);
    startGame();
  }

  public void startGame() {
    /* Initialize the game thread. */
    GameThread = new GameThread();
    GameThread.start();
  }

  private class GameThread extends Thread {
    public void run() {
      game.run();
    }
  }


Next I have to use the inner class to use Thread but when I try to start it gives me his error:
1  
2  
Exception in thread "main" java.lang.ClassNotFoundException: Game_Management
   at java.net.URLClassLoader$1.run(URLClassLoader.java:200)


How do I start a thread and do therun method in another class?
Error sorted, I put package in my classes so it couldn't find the class anymore.

alsoo is it smart to put those 2 things appart?
For more Info I created a javadoc Documentation and I put the src online
Any comment is welcome Wink
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #1 - Posted 2007-08-31 16:16:34 »

If you want to pause the game... simply stop calling tick() (or whatever your logic method is called)... render the game as usual and if paused, render "paused" on top.

It really can be this simple. Smiley

弾幕 ☆ @mahonnaiseblog
Offline stef569

Junior Devvie





« Reply #2 - Posted 2007-08-31 16:43:27 »

srry, i don't see it   Cool

When the guy behind the keybord pressed p he wants to pauze.
so if p=true then stop calling my run loop. No more code runs nothing happens.
Now he returns and presses p again to go on, but how do i continue, there is nothing there? I stopped my loop...

or do you mean keep on running all the code except the run function but wouldn't that be a waste?

Whats wrong with thread.pauze? Huh

alsoo i found this page http://www.theorphys.science.ru.nl/people/fasolino/sub_java/pendula/Classes/nl/kun/Engine3D/TickTimer.html wich has a counter and it looks excactly what i need, but it's not within the jdk (i can't find it...)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #3 - Posted 2007-08-31 16:52:40 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
while(running){
  if(paused)
    checkUnpause();
  else
    tick();
  render();
  if(paused)
    renderPauseShizzle();
}

弾幕 ☆ @mahonnaiseblog
Offline stef569

Junior Devvie





« Reply #4 - Posted 2007-08-31 17:09:41 »

I see  Grin
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.

trollwarrior1 (32 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (64 views)
2014-11-07 19:57:14

TehJavaDev (69 views)
2014-11-03 22:04:50

BurntPizza (67 views)
2014-11-03 18:54:52

moogie (82 views)
2014-11-03 06:22:04

CopyableCougar4 (82 views)
2014-11-01 23:36:41
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!