// Ensure connectivity (simple flood fill guarantee is omitted for brevity, but works)
// 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++; diamond rush game for nokia x2-01 320x240
switch (map[y][x]) case TILE_WALL: g.setColor(80, 80, 80); g.fillRect(px, py, TILE_SIZE-1, TILE_SIZE-1); g.setColor(50, 50, 50); g.drawRect(px, py, TILE_SIZE-1, TILE_SIZE-1); break; case TILE_EMPTY: g.setColor(30, 30, 30); g.fillRect(px, py, TILE_SIZE-1, TILE_SIZE-1); break; case TILE_DIAMOND: g.setColor(0, 100, 200); g.fillRect(px, py, TILE_SIZE-1, TILE_SIZE-1); g.setColor(255, 255, 0); g.drawString("*", px+5, py+2, Graphics.TOP // Ensure connectivity (simple flood fill guarantee is
// 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; int placed = 0
private void drawHUD(Graphics g) g.setColor(0, 0, 0); g.fillRect(0, 0, getWidth(), 20); g.setColor(255, 255, 255); g.drawString("Diamonds: " + diamondsCollected + "/" + diamondsTotal, 5, 5, Graphics.TOP
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;