Hi Guys I am developing game a am not ale to set the next displayable screen, Kindly review the code and suggest corrections.
--------------------------------------
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
public class a extends MIDlet {
public Display display;
public game abc;
public a() {
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
System.out.println("GAme ended");
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
display=Display.getDisplay(this);
try
{
b abc=new b();
abc.start();
display.setCurrent(abc);
}
catch(Exception e)
{
}
}
}
----------------------------------------
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class b extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay; // To give thread consistency
private int currentX, currentY; // To hold current position of the 'X'
private int width; // To hold screen width
private int height; // To hold screen height
public a parent;
private Display display;
private Sprite sprite;
private game abc;
private Image image;
private LayerManager layers;
// Constructor and initialization
public b() throws Exception {
super(true);
width = getWidth();
abc=new game();
//parent=new a();
abc.start();
this.setFullScreenMode(true);
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 100;
// Load Images to Sprites
try {
image = Image.createImage("/a.png");
} catch (Exception e) {
}
sprite = new Sprite(image,83,23);
sprite.setPosition(10,100 );
layers = new LayerManager();
layers.append(sprite);
}
// Automatically start thread for game loop
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try {
Thread.sleep(delay);
} catch (InterruptedException ie) {
}
}
}
// Method to Handle User Inputs
private void input() {
int keyStates = getKeyStates();
//sprite.setFrame(0);
// Left
if ((keyStates & LEFT_PRESSED) != 0) {
sprite.nextFrame();
}
// Right
if ((keyStates & RIGHT_PRESSED) != 0)
{
sprite.prevFrame();
}
// Up
if ((keyStates & UP_PRESSED) != 0) {
}
// Down
if ((keyStates & DOWN_PRESSED) != 0)
{
}
if ((keyStates & FIRE_PRESSED) != 0)
{
int a =sprite.getFrame();
if (a==1)
{
System.out.println("Singh");
}
else if(a==0)
{
System.out.println("Game Started)");
display.setCurrent(abc);
}
else if(a==4)
{
try
{
System.out.println("Exit prerssed");
parent.destroyApp(true);
}
catch(Exception e)
{
}
}
}
}
// Method to Display Graphics
private void drawScreen(Graphics g) {
g.setColor(0xFF0000);
g.fillRect(0, 0, getWidth(), getHeight());
// display sprites
layers.paint(g, 0, 0);
flushGraphics();
}
}
----------------------------------------------------------
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class game extends GameCanvas implements Runnable {
private boolean isPlay; // Game Loop runs when isPlay is true
private long delay;
// Constructor and initialization
public game() throws Exception {
super(true);
this.setFullScreenMode(true);
delay = 10;
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() {
isPlay = false;
}
// Main Game Loop
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try {
Thread.sleep(delay);
} catch (InterruptedException ie) {
}
}
}
// Method to Handle User Inputs
private void input() {
}
// Method to Display Graphics
private void drawScreen(Graphics g) {
g.setColor(255,10,10);
g.fillRect(0, 0, getWidth(), getHeight());
flushGraphics();
}
}
i am not able to navigate it to next screen..
kindly help.
