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...
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 :
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. :)