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

    Default Implementing bluetooth/network code (beginners).

    *duplicate post, but nobody can help in the New to Java forum so am trying here instead*

    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.

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

    Default

    68 views but nobody has any suggestions? :(

  3. #3
    peter_budo is offline Member
    Join Date
    Dec 2010
    Posts
    49
    Rep Power
    0

    Default

    1. Start game
    2. Search for available devices
    3. Attempt to establish connection
    4. Once connected start passing data

    So looking at what you provided I would place it in PongCanvas in start(). First searching for device, then connecting and only after that start with sprites and other bits associated with game.

    PS: Moaning about not getting reply wouldn't help you. There is no restriction that people cannot view it if they do not know answer.
    PS2: Just foreword warning, I'm holidays so there is possibility that my next reply will come only after 29th Dec.

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

    Default

    I'll figure it out, was just looking to save some time. No worries though, am sure it's not as complex to do as I'm making it out to be.

Similar Threads

  1. Replies: 2
    Last Post: 12-14-2010, 05:10 PM
  2. Replies: 7
    Last Post: 05-02-2010, 11:35 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
  •