// Tile types private static final byte TILE_EMPTY = 0; private static final byte TILE_WALL = 1; private static final byte TILE_DIAMOND = 2; private static final byte TILE_PLAYER = 3; private static final byte TILE_EXIT = 4; private static final byte TILE_EXIT_OPEN = 5;
public void startApp() running = true; gameThread = new Thread(this); gameThread.start();
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); diamond rush game for nokia x2-01 320x240
private byte[][] map = new byte[HEIGHT][WIDTH]; private int playerX, playerY; private int diamondsTotal, diamondsCollected; private boolean exitOpen;
public DiamondRush() display = Display.getDisplay(this); canvas = new GameCanvas(); exitCommand = new Command("Exit", Command.EXIT, 1); canvas.addCommand(exitCommand); canvas.setCommandListener(this); // Tile types private static final byte TILE_EMPTY
// Place diamonds (count = 15-25) diamondsTotal = 15 + random.nextInt(11); int placed = 0; while (placed < diamondsTotal) int x = 1 + random.nextInt(WIDTH-2); int y = 1 + random.nextInt(HEIGHT-2); if (map[y][x] == TILE_EMPTY && !(x == 1 && y == 1)) map[y][x] = TILE_DIAMOND; placed++;
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
public void handleInput() int key = getGameAction(getKeyStates());
// 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;
protected void keyPressed(int keyCode)
// Map dimensions private static final int WIDTH = 15; // 15 tiles wide private static final int HEIGHT = 12; // 12 tiles high private static final int TILE_SIZE = 20; // 20x20 pixels (20*15=300, 20*12=240)