Results 1 to 3 of 3
  1. #1
    SM2010 is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default Generic question on implementing bluetooth/net code

    Hi folks - as a learning exercise, I'm trying to write a very simple J2ME game project (pong) playable via bluetooth, however hopefully my problem is high level enough that it can be answered by non-J2ME'ers too. :)

    What I have up to now is 2 'sub' projects, the pong game and also a skeleton bluetooth client/server. Both of which are fairly straightforward and are working, in their own separate right.

    Now however I want to 'plug' the bluetooth Client code (I'll keep Server as a separate class for now) into the game code, but I'm a bit stumped how & more specifically where to do it.

    Up to now, for instance, my game Midlet looks like this...

    Java Code:
    public class Pong extends MIDlet {
    	public Pong() { 
    	  pongCanvas = new PongCanvas(); 
    	}
    
    	public void startApp() {
    		Display display =Display.getDisplay(this);
    		pongCanvas.start(); 
    		display.setCurrent(pongCanvas);
    	}
    
    	public void pauseApp() { }
    	public void destroyApp(boolean unconditional) { }
    	private static PongCanvas pongCanvas; 
    }
    And then in pongCanvas is the game thread :

    Java Code:
    	public void run() {
    		while(true) {
    			updateScreen(getGraphics());
    			try { Thread.sleep(sleepTime); }
    			catch (Exception e) { }
    		}
    	}
    
    	public void start() {
                    initSprites();
    		Thread runner = new Thread(this);
    		runner.start();
    	}
    My assumption is I need to add an output.write() (or similar) call in the game loop, to write out whatever info I want sending as part of the game.

    What I don't know, or am failing miserably to grasp, is how to get the Client up and running alongside the game, and how to then access the client methods from within my game class.

    Do I need to start the Client in the Midlet class code, or should I just add the Client methods to my game class, and make one big game/client hybrid class?

    I'm confused on the structure really, how & where do you generally plug network code into your game. I'm struggling to 'visualise' how the final Midlet/Game/Client classes should look, if that makes any sense.

    thanks in advance for any tips. :)
    Last edited by SM2010; 12-13-2010 at 03:47 PM.

  2. #2
    SM2010 is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default

    anyone help? before this sinks down to page 2... :)

  3. #3
    SM2010 is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

Similar Threads

  1. Java Generic Container Question - please help!!!
    By zhoujackji in forum New To Java
    Replies: 3
    Last Post: 11-13-2010, 12:12 PM
  2. generic code
    By mac in forum New To Java
    Replies: 4
    Last Post: 05-27-2010, 06:06 PM
  3. java code for bluetooth.
    By rainfan in forum Java Applets
    Replies: 4
    Last Post: 01-13-2010, 06:11 AM
  4. Replies: 0
    Last Post: 02-26-2009, 09:14 PM
  5. Trouble implementing part of code into GUI
    By Flaresplitz in forum New To Java
    Replies: 1
    Last Post: 12-21-2008, 08:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •