public void run() { while (running) { if (gameState == STATE_PLAYING) canvas.handleInput(); canvas.repaint(); try Thread.sleep(50); catch (Exception e) {} } }
protected void keyPressed(int keyCode)
public void commandAction(Command c, Displayable d) if (c == exitCommand) destroyApp(true); notifyDestroyed(); diamond rush game for nokia x2-01 320x240
private void drawMenu(Graphics g) g.setColor(0, 0, 0); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(255, 215, 0); g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE)); g.drawString("DIAMOND RUSH", getWidth()/2, 40, Graphics.HCENTER); g.setColor(255, 255, 255); g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_PLAIN, Font.SIZE_MEDIUM)); g.drawString("Press OK to Start", getWidth()/2, 120, Graphics.HCENTER); g.drawString("Use 2,4,6,8 to move", getWidth()/2, 160, Graphics.HCENTER); g.drawString("5 to pick diamonds", getWidth()/2, 190, Graphics.HCENTER);
private void generateRandomLevel() // Fill with walls for (int y = 0; y < HEIGHT; y++) for (int x = 0; x < WIDTH; x++) map[y][x] = TILE_WALL; public void run() { while (running) { if
/* * Diamond Rush for Nokia X2-01 (320x240) * Controls: 2=Up, 8=Down, 4=Left, 6=Right, 5=Pick Diamond, * = Restart * Goal: Collect all diamonds to unlock the exit door. */ import javax.microedition.lcdui. ; import javax.microedition.midlet. ; import java.util.Random;
private void newGame() generateRandomLevel(); diamondsCollected = 0; exitOpen = false; gameState = STATE_PLAYING; ; import java
private Random random = new Random();