Diamond Rush Game For Nokia X2-01 320x240 -

private Random random = new Random();

public void pauseApp() {} public void destroyApp(boolean unconditional) running = false;

private void movePlayer(int dx, int dy)

public class DiamondRush extends MIDlet implements CommandListener, Runnable { private Display display; private GameCanvas canvas; private Command exitCommand; private boolean running; private Thread gameThread; diamond rush game for nokia x2-01 320x240

private void drawWin(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("YOU WIN!", getWidth()/2, 80, Graphics.HCENTER); g.setColor(255, 255, 255); g.drawString("Press * to play again", getWidth()/2, 150, Graphics.HCENTER);

protected void paint(Graphics g) if (gameState == STATE_MENU) drawMenu(g); else if (gameState == STATE_PLAYING) drawGame(g); drawHUD(g); else if (gameState == STATE_WIN) drawWin(g); else if (gameState == STATE_GAME_OVER) drawGameOver(g);

/* * 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 Random random = new Random(); public void

private void drawGame(Graphics g) // Draw map for (int y = 0; y < HEIGHT; y++) for (int x = 0; x < WIDTH; x++) int px = x * TILE_SIZE; int py = y * TILE_SIZE;

public void startApp() running = true; gameThread = new Thread(this); gameThread.start();

public void handleInput() int key = getGameAction(getKeyStates()); ; import java

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);

// Place exit door at bottom-right area int exitX = WIDTH-2, exitY = HEIGHT-2; while (map[exitY][exitX] != TILE_EMPTY && exitX > 1 && exitY > 1) exitX--; exitY--; map[exitY][exitX] = TILE_EXIT;

if (key == Canvas.UP) movePlayer(0, -1); else if (key == Canvas.DOWN) movePlayer(0, 1); else if (key == Canvas.LEFT) movePlayer(-1, 0); else if (key == Canvas.RIGHT) movePlayer(1, 0); else if (key == Canvas.FIRE) // Manually pick diamond if adjacent (simple logic) for (int dy=-1; dy<=1; dy++) for (int dx=-1; dx<=1; dx++) if (Math.abs(dx)+Math.abs(dy)==1) int x = playerX+dx, y = playerY+dy; if (x>=0 && x<WIDTH && y>=0 && y<HEIGHT && map[y][x]==TILE_DIAMOND) movePlayer(dx, dy); return;