Files
2026-04-30 02:14:25 +00:00

463 lines
15 KiB
JavaScript

require('dotenv').config();
const { pool } = require('../src/models/db');
const { generateGame } = require('../src/utils/claude');
// Games that need fixing (Pong ID:16 and Minesweeper ID:22 work well)
const gamesToFix = [
{
id: 14,
title: "Snake",
prompt: `Create a classic Snake game. The snake starts in the center moving right.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Snake moves continuously in current direction
- Game starts immediately when page loads
- Use requestAnimationFrame for smooth animation
CONTROLS (implement ALL):
- Desktop: Arrow keys change direction (prevent 180° turns)
- Mobile: Touch/swipe detection - swipe in any direction to turn the snake
- Add visible on-screen arrow buttons for mobile (semi-transparent, positioned at bottom)
GAMEPLAY:
- Snake is green segments on a dark grid background
- Red apple appears randomly, eating it grows snake by 1 and adds 10 points
- Game over when hitting walls or self
- Show score in top-left corner
- Game over screen shows "Game Over! Score: X" with "Tap to Restart" button
- Speed increases slightly every 50 points
MOBILE ON-SCREEN CONTROLS:
Add a d-pad style control at the bottom of the screen:
- Four arrow buttons (up, down, left, right) arranged in a cross pattern
- Buttons should be 50px, semi-transparent white with dark arrows
- Position fixed at bottom center of game area
Keep game area square and centered. Use canvas for rendering.`
},
{
id: 15,
title: "Tetris",
prompt: `Create a Tetris falling block puzzle game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Pieces fall automatically at steady pace
- Game starts immediately when page loads
- Use requestAnimationFrame for game loop
CONTROLS (implement ALL):
- Desktop: Left/Right arrows move piece, Up arrow rotates, Down arrow soft drop, Space hard drop
- Mobile: Add visible touch buttons at bottom of screen
MOBILE CONTROLS (REQUIRED):
Create a control panel at bottom with these buttons:
- Left arrow button (move left)
- Right arrow button (move right)
- Rotate button (clockwise rotation)
- Down button (soft drop)
- Drop button (hard drop)
Buttons: 45px size, semi-transparent, arranged in a row
GAMEPLAY:
- 10 columns, 20 rows playing field
- 7 tetromino shapes (I, O, T, S, Z, J, L) with different colors
- Completed lines clear with flash effect
- Score: 1 line=100, 2=300, 3=500, 4=800 points
- Show next piece preview on the side
- Game over when pieces reach top
- Speed increases every level (10 lines = 1 level)
Use canvas rendering. Game area should be centered with controls below.`
},
{
id: 17,
title: "Breakout",
prompt: `Create a Breakout/Brick Breaker arcade game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Ball bounces continuously once launched
- Paddle follows mouse/touch position smoothly
- Game starts with ball on paddle, click/tap to launch
CONTROLS:
- Desktop: Mouse movement controls paddle position, click to launch ball
- Mobile: Touch and drag anywhere to move paddle, tap to launch ball
- Paddle should follow finger/mouse X position instantly
GAMEPLAY:
- 8 rows of colored bricks at top (rainbow colors)
- White paddle at bottom, ball is white circle
- Ball bounces off walls, paddle, and bricks
- Each brick hit = 10 points, brick disappears
- Ball angle changes based on where it hits paddle (edges = sharper angle)
- Lose a life if ball falls below paddle (3 lives total)
- Win when all bricks destroyed
- Show score and lives at top
VISUAL:
- Black background
- Colorful bricks in rows (red, orange, yellow, green, blue, purple)
- Paddle is white rectangle, rounded corners
- Ball leaves a short trail effect
- Bricks flash when hit before disappearing
Use canvas. No on-screen buttons needed - paddle follows touch/mouse directly.`
},
{
id: 18,
title: "Space Invaders",
prompt: `Create a Space Invaders shooting game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Aliens move and player can shoot immediately
- Smooth 60fps animation with requestAnimationFrame
CONTROLS (implement ALL):
- Desktop: Left/Right arrows move ship, Space to shoot
- Mobile: Touch left half of screen to move left, right half to move right
- Mobile: Tap center area or double-tap anywhere to shoot
- Add visible Left/Right buttons at bottom corners and Fire button in center
MOBILE CONTROLS (REQUIRED):
- Left button: bottom-left corner, 60px, arrow pointing left
- Right button: bottom-right corner, 60px, arrow pointing right
- Fire button: bottom-center, 70px, red circle with "FIRE" text
All buttons semi-transparent
GAMEPLAY:
- 5 rows of 8 aliens that move side-to-side and drop down
- Player ship at bottom can move and shoot upward
- One bullet on screen at a time
- Aliens occasionally drop bombs
- 3 lives, hit by bomb = lose life
- Bottom row aliens = 10pts, increasing 10pts per row up
- Aliens speed up as fewer remain
- Wave complete when all aliens destroyed
VISUAL:
- Black space background with twinkling stars
- Green player ship (triangle)
- Aliens are simple pixel-art style (different shapes per row)
- White bullets, red alien bombs
Use canvas rendering.`
},
{
id: 19,
title: "Pac-Man",
prompt: `Create a simplified Pac-Man maze game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Pac-Man moves continuously in set direction
- Simple maze (not full Pac-Man complexity)
- Smooth animation at 60fps
CONTROLS (implement ALL):
- Desktop: Arrow keys set movement direction
- Mobile: Swipe in direction to change Pac-Man's direction
- Add on-screen d-pad for mobile (arrow buttons in cross pattern)
MOBILE CONTROLS (REQUIRED):
D-pad at bottom center:
- Up, Down, Left, Right buttons arranged in cross
- Each button 50px, semi-transparent
- Pac-Man turns at next opportunity when button pressed
GAMEPLAY:
- Simple maze with blue walls (use a basic grid maze, 15x15)
- Yellow dots throughout maze (10 points each)
- 4 large power pellets in corners (50 points, makes ghosts vulnerable)
- 4 colored ghosts that chase Pac-Man
- When powered up (8 seconds), ghosts turn blue and can be eaten (200 pts)
- Lose life if touched by non-blue ghost (3 lives)
- Level complete when all dots eaten
VISUAL:
- Black background, blue maze walls
- Yellow Pac-Man with chomping animation
- Ghosts: Red, Pink, Cyan, Orange with googly eyes
- Dots are small white circles, power pellets are large and flashing
Use canvas. Keep maze simple for playability.`
},
{
id: 20,
title: "Flappy Bird",
prompt: `Create a Flappy Bird style game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Bird flaps on ANY input (tap, click, spacebar, any key)
- Gravity pulls bird down constantly
- Game starts with "Tap to Start" message
CONTROLS (SIMPLE):
- ANY tap, click, touch, or key press = bird flaps upward
- That's the only control needed
- Make sure touchstart event is captured on the entire game canvas
GAMEPLAY:
- Bird on left side of screen, pipes scroll from right
- Pipes have gap in middle to fly through
- Each pipe passed = 1 point
- Game over if bird hits pipe, ground, or ceiling
- Bird rotates based on velocity (nose up when rising, down when falling)
- After game over, show score and "Tap to Restart"
PHYSICS:
- Gravity: bird falls at accelerating rate
- Flap: gives instant upward velocity
- Bird should feel "floaty" but responsive
- Pipe gap should be generous (bird height * 4)
VISUAL:
- Light blue sky background with simple clouds
- Green pipes from top and bottom
- Yellow/orange bird with wing flap animation
- Ground at bottom with scrolling grass texture
- Large score number at top center
Use canvas. Entire canvas should respond to touch events.`
},
{
id: 21,
title: "2048",
prompt: `Create the 2048 sliding puzzle game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Tiles slide and merge correctly
- Touch swipe detection must work reliably
- Game should feel smooth and responsive
CONTROLS:
- Desktop: Arrow keys slide all tiles in that direction
- Mobile: Swipe gestures (detect swipe direction on touchend)
- Swipe detection: track touchstart and touchend positions, determine direction
SWIPE IMPLEMENTATION:
- On touchstart: record start X,Y
- On touchend: calculate delta X,Y
- If |deltaX| > |deltaY| and |deltaX| > 30px: horizontal swipe
- If |deltaY| > |deltaX| and |deltaY| > 30px: vertical swipe
- Determine direction based on positive/negative delta
GAMEPLAY:
- 4x4 grid of tiles
- Start with two "2" tiles in random positions
- Sliding merges matching adjacent tiles (2+2=4, 4+4=8, etc)
- After each move, new tile (90% chance of 2, 10% chance of 4) appears
- Score increases by merged tile value
- Game over when no moves possible
- Win message at 2048 but allow continuing
VISUAL:
- Clean, modern design with rounded tiles
- Each number has distinct background color:
- 2: #eee4da, 4: #ede0c8, 8: #f2b179, 16: #f59563
- 32: #f67c5f, 64: #f65e3b, 128+: #edcf72 to #edc22e
- Tiles animate when sliding and merging (CSS transitions)
- Large, bold numbers on tiles
- Score display at top
Use div-based grid with CSS transitions for smooth animations.`
},
{
id: 23,
title: "Asteroids",
prompt: `Create a classic Asteroids space shooter.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Ship rotates and thrusts with momentum-based physics
- Screen wrapping (go off one edge, appear on opposite)
- Smooth 60fps gameplay
CONTROLS (implement ALL):
- Desktop: Left/Right rotate ship, Up thrusts forward, Space shoots
- Mobile: On-screen virtual joystick or buttons
MOBILE CONTROLS (REQUIRED):
Left side: Rotation buttons (two buttons: rotate left, rotate right)
Right side: Action buttons (Thrust button, Fire button)
All buttons 50-60px, semi-transparent, positioned at bottom
GAMEPLAY:
- Ship starts in center, 3 lives
- Large asteroids split into 2 medium, medium into 2 small
- Points: Large=20, Medium=50, Small=100
- Ship has inertia - keeps drifting after thrust stops
- Bullets travel straight and wrap around screen
- Collision with asteroid = lose life, brief invincibility after respawn
- Clear all asteroids = next wave with more asteroids
PHYSICS:
- Ship rotation is instant
- Thrust adds velocity in facing direction
- Small friction to eventually slow down
- Asteroids drift at random angles and speeds
VISUAL:
- Black background with small white stars
- Ship is white triangle outline (vector style)
- Asteroids are irregular polygon outlines
- Bullets are small white dots
- Explosion particles when things are destroyed
Use canvas with vector-style graphics (lines, not filled shapes).`
},
{
id: 24,
title: "Frogger",
prompt: `Create a Frogger road-crossing game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Grid-based hop movement (one square per input)
- Cars and logs move continuously
- Simple but playable level design
CONTROLS:
- Desktop: Arrow keys to hop in that direction
- Mobile: On-screen d-pad buttons OR swipe to hop
MOBILE CONTROLS (REQUIRED):
D-pad at bottom:
- Up/Down/Left/Right buttons in cross pattern
- Each button 55px, semi-transparent
- Each tap = one hop in that direction
GAMEPLAY:
- Frog starts at bottom, goal is to reach top
- Bottom half: Road with cars/trucks moving left and right
- Top half: River with logs and turtles moving left and right
- Hit by car = lose life
- Fall in water (miss a log) = lose life
- Ride logs/turtles to cross river
- 5 home spots at top to fill
- Fill all 5 = level complete
- 3 lives, timer countdown (30 seconds per frog)
LEVEL DESIGN:
- Row 1 (bottom): Safe starting grass
- Rows 2-4: Roads with vehicles (alternate directions)
- Row 5: Safe middle grass
- Rows 6-8: River with logs/turtles
- Row 9 (top): Home bases with lily pads
VISUAL:
- Green frog (top-down view)
- Gray roads with lane markings
- Blue water
- Brown logs, green turtles
- Colorful cars/trucks
- Green grass safe zones
Use canvas, grid-based movement.`
},
{
id: 25,
title: "Simon Says",
prompt: `Create a Simon Says memory pattern game.
CRITICAL REQUIREMENTS:
- Game MUST work on both desktop and mobile
- Buttons must be large and easy to tap on mobile
- Clear visual and audio-like feedback when buttons activate
- Pattern plays automatically, then waits for player input
CONTROLS:
- Desktop: Click the colored buttons OR use keys 1,2,3,4
- Mobile: Tap the colored buttons (make them big!)
GAMEPLAY:
- Four large colored buttons (Red, Blue, Green, Yellow)
- Arranged in 2x2 grid or quadrants of a circle
- Computer shows pattern by lighting up buttons in sequence
- Player must repeat the pattern by pressing buttons
- Each round adds one more to the sequence
- Wrong button = game over, show final score (rounds completed)
- Display current round number
BUTTON BEHAVIOR:
- When showing pattern: button lights up brightly for 0.5s, 0.3s gap between
- When player presses: button lights up while pressed
- Each button should have distinct appearance when lit vs unlit
- Consider adding different tones/sounds for each button (optional)
VISUAL:
- Large, touchable buttons (at least 120px each on mobile)
- Distinct colors: Red (#ff4444), Blue (#4444ff), Green (#44ff44), Yellow (#ffff44)
- Buttons dim when inactive, bright when active
- Center area shows round number and "Watch..." or "Your turn!" message
- Dark background to make colors pop
- "Start Game" button initially, "Play Again" after game over
LAYOUT:
- Buttons should fill most of the screen
- 2x2 grid with small gaps
- Score/round display above or below buttons
- Make sure buttons are finger-friendly size
Use div-based buttons with CSS for the glow effects. No canvas needed.`
}
];
async function fixGame(gameData) {
console.log(`\nRegenerating: ${gameData.title} (ID: ${gameData.id})...`);
try {
const result = await generateGame(gameData.prompt);
if (!result.success) {
console.error(` Failed: ${result.error}`);
return false;
}
// Update the game in database
await pool.query(
`UPDATE games SET game_code = $1, prompt = $2 WHERE id = $3`,
[result.code, gameData.prompt, gameData.id]
);
console.log(` Success: ${gameData.title} updated`);
return true;
} catch (error) {
console.error(` Error: ${error.message}`);
return false;
}
}
async function main() {
console.log('Fixing games with improved controls...');
console.log(`Games to fix: ${gamesToFix.length}`);
console.log('Using Claude Sonnet 4 for generation.\n');
let successCount = 0;
for (const game of gamesToFix) {
const success = await fixGame(game);
if (success) successCount++;
// Delay between API calls
await new Promise(resolve => setTimeout(resolve, 2000));
}
console.log('\n========================================');
console.log(`COMPLETE: ${successCount}/${gamesToFix.length} games fixed`);
console.log('========================================');
await pool.end();
process.exit(0);
}
main().catch(err => {
console.error('Fatal error:', err);
process.exit(1);
});