Get new ideas by email. Join 3.9k+ readers.

Diamond Rush Game For Nokia X2-01 320x240 (2027)

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;

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

private void restartGame() newGame();

public void pauseApp() {} public void destroyApp(boolean unconditional) running = false; diamond rush game for nokia x2-01 320x240

private void drawGameOver(Graphics g) g.setColor(0, 0, 0); g.fillRect(0, 0, getWidth(), getHeight()); g.setColor(255, 0, 0); g.drawString("GAME OVER", getWidth()/2, 80, Graphics.HCENTER); g.setColor(255, 255, 255); g.drawString("Press * to restart", getWidth()/2, 150, Graphics.HCENTER);

Save the code as DiamondRush.java , compile with WTK (Wireless Toolkit), and package as a .jar file.

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

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

class GameCanvas extends Canvas private int menuSelection = 0;

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); if (key == Canvas.UP) movePlayer(0

// Dig pathways (simple maze-like open space) for (int y = 1; y < HEIGHT-1; y++) for (int x = 1; x < WIDTH-1; x++) if (random.nextInt(100) < 70) // 70% open space map[y][x] = TILE_EMPTY; else map[y][x] = TILE_WALL;

// Create outer walls for (int x = 0; x < WIDTH; x++) map[0][x] = TILE_WALL; map[HEIGHT-1][x] = TILE_WALL; for (int y = 0; y < HEIGHT; y++) map[y][0] = TILE_WALL; map[y][WIDTH-1] = TILE_WALL;

public void run() { while (running) { if (gameState == STATE_PLAYING) canvas.handleInput(); canvas.repaint(); try Thread.sleep(50); catch (Exception e) {} } }

// Game states private static final int STATE_MENU = 0; private static final int STATE_PLAYING = 1; private static final int STATE_WIN = 2; private static final int STATE_GAME_OVER = 3; private int gameState = STATE_MENU;

// Place player at (1,1) map[1][1] = TILE_PLAYER; playerX = 1; playerY = 1;