This is a big project — a World Cup dream team matchmaking game with dice rolls, player drafting, and match simulation. Let me plan the architecture first, then build it step by step.
Architecture Plan:
- Game States: Start Screen → Dice Roll (get random WC team) → Player Draft (pick players by position) → AI Draft → Match Simulation → Game Over (results + high scores)
- Components: App shell with state machine, DiceRoller, PlayerDraft, MatchSim, ScoreBoard, HighScores
- Data: World Cup teams from various years with real-ish player names and ratings
- Effects: Screen shake, particles, animations via CSS + canvas
- Storage: LocalStorage for high scores
Let me start by exploring the existing project structure and then build everything.
Good. Now I have the full picture. Let me build this game. I'll create:
src/data/teams.ts - World Cup team data with players and ratings
src/game/engine.ts - Core game logic, match simulation
src/components/ - All UI components
- Update
src/App.tsx - Main game shell
- Update
index.html - Title
Let me start building. I'll create the data file first with real World Cup teams and players, then the game engine, then all the UI components.
Now the game engine:
Minor unused import. Let me fix that and continue building the components. Let me now create all the UI components and the main App:
Now let me create the main CSS and App in one go, then create all the components. Let me write all the files:
Now let me create all the React components. I'll create them as individual files:
Now create the Start Screen:
Now the Dice Roll component:
Now the Player Draft component (the most complex UI component):
Now the Match Simulator component:
Now the Game Over / Results screen:
Now the main App that ties it all together:
Now update the HTML title:
Let me now try to build and see what errors we get:
Build succeeds. But I notice the AI opponent still uses hardcoded players in App.tsx rather than drafting from the actual rolled teams. Let me fix that — the opponent should also get a draft from the same pool. Let me also make the AI draft happen properly in the PlayerDraft component.
Looking at the current code, the opponent team has its own hardcoded lineup. The user's draft does use the rolled teams. The AI draft in PlayerDraft is populating aiPlayers but we never use those. Let me make the opponent use the AI-drafted players from the same pool. Let me update the flow so the AI draft is actually used:
I need to pass the AI lineup to the App. Let me update the onDraftComplete to also return the AI lineup, and update App.tsx accordingly:
Now update App.tsx to accept the opponent lineup:
Now update the match phase to use opponentLineup:
Also need to reset opponentLineup on restart:
Now let me build again:
The build passes. But I now notice a problem — the AI draft in PlayerDraft currently drafts all 4 positions simultaneously as the user moves through positions, but the AI should only draft for the current position. Let me review and improve the AI draft logic and also make sure the fallback players have proper IDs. Actually, looking more carefully, the AI draft is working per-position. The issue is that the AI draft happens per position when the user visits that position, which is correct. But the AI drafts ALL required slots for that position (e.g., 4 defenders at once), which is fine.
However, there's a potential bug: the AI draft uses draftedIds which doesn't include user-picked players when the AI draft effect fires (since the effect runs when currentPos changes and draftedIds is in the dependency). Actually wait - the AI draft effect doesn't list draftedIds as a dependency, so it only fires on mount and currentPos change. That's okay.
But there's a more subtle issue: the AI picks from teams.flatMap(t => t.players) which includes all players from all teams, and filters out draftedIds. But the AI picks ALL required slots at once (e.g., all 4 defenders) before the user picks theirs. This means AI gets the best defenders! That should actually be: AI picks after the user has picked for that position. Let me fix this so AI drafts its remaining slots only after the user finishes each position.
Let me re-examine the flow:
- User visits GK position -> AI drafts 1 GK -> User picks 1 GK -> moves to DEF
- User visits DEF -> AI drafts 4 DEF -> User picks 4 DEF -> moves to MID
etc.
This means AI always picks the best players before the user. That's okay for game balance, actually — the AI should be competitive. But it would be better if they're interleaved: AI picks one, user picks one, etc. However, for simplicity and gameplay pace, the current approach is fine — the user still sees all available players and can pick their favorites.
Let me also verify the AI properly skips already-drafted players. The AI draft effect checks !draftedIds.has(p.id) but draftedIds at the point the effect fires may not have the user's picks for the current position. Looking at the effect dependencies: [currentPos, aiDrafting]. It doesn't depend on draftedIds. So the closure captures the old value. Let me fix this:
I see the issue — the AI draft effect uses draftedIds which is stale in the closure. I need to use a ref for draftedIds or change the effect to use a functional update approach. Let me use a ref:
Now update the AI draft to use the ref:
Good. Now let me think about a few more polish items that would really make the game shine:
-
The AI draft currently fires immediately when the user enters a position and drafts ALL slots. The user might not have picked any yet. This means the AI gets the best picks. That's actually fine for game balance.
-
The match simulator needs to show score updates more dramatically
-
I should add a formation visualization for the user's lineup
-
The game's match simulation should show the opponent's team name more specifically (which teams they drafted from)
Let me also add a formation pitch visual to the match screen and improve the overall experience. Let me also fix a few things: the AI draft should properly handle the case where not enough players exist. And I should add a formation view.
Let me create a pitch formation component and enhance the match screen:
Now let me update the MatchSim to include the formation view. Let me also make the match simulation more exciting:
Let me rewrite MatchSim with formation view and better UX:
Build passes. Now let me review the full flow once more. I want to make sure the game loop is tight and fun. Let me also add touch support for speeding up the match (tapping anywhere), and make sure the match events are interesting.
Let me also add a "tap to fast forward" feature to MatchSim, and make the match start faster:
Let me add the tap handler to the container and use fastForward:
Now add the tap handler on the container and use fastForward for visual feedback:
Good, builds clean. Let me now review the full flow once more. There's one thing I want to improve: the AI should also draft from the rolled teams. Currently, the AI draft in PlayerDraft does use rolled teams, and the opponent lineup is built from the AI's drafted players. But there's a subtle issue: the AI drafts ALL slots for a position immediately when user enters that position, which means AI gets the best players first. This is fine but we should make sure there are enough players. With 3 teams × 10 players = 30 players total, and 11 per team (user + AI = 22), that's enough.
However, there are only 1 GK per team = 3 GKs total, and we need 2 (user + AI). That works.
DEF: 4 per team = 12, need 8. Works.
MID: 3 per team = 9, need 6. Works.
FWD: 2 per team = 6, need 4. Works.
Great. But there's a potential issue: with 3 teams, each team has exactly 1 GK, and the AI drafts 1 GK, leaving 2 for the user. That works.
Let me also improve one more thing: the AI draft should only happen AFTER the user has finished picking their players for that position. Currently it happens right when the position is entered. Let me change it so the AI drafts after the user completes their picks for that position:
Actually, let me change the approach: the AI should draft only after the user finishes their picks for each position. This makes it more fair and interesting. Let me refactor:
Wait, now the AI draft only happens when userCurrent >= currentSlotMax. But the AI draft effect depends on selectedPlayers, and when the user finishes a position, currentPos is auto-advanced. The auto-advance happens inside handlePick via setTimeout(() => setCurrentPos(nextPos), 300). This means when the position changes, the AI draft for the OLD position would fire (since it's now checking the NEW position).
Let me rethink this. The simpler approach: AI drafts happen after user finishes a position, and the auto-advance delays. But actually, the current setup may work because:
- User is on GK, picks 1 GK → auto-advance DEF is queued
- The AI draft effect for GK fires (since user has completed GK picks) → AI picks 1 GK
- 300ms later, currentPos changes to DEF
- Now on DEF: user picks 4 DEF, AI draft fires after user completes 4 picks
This should work since the AI GK draft fires before the position switch. But the handlePick has a stale closure issue with the AI draft check. Actually, let me keep it simpler - let the AI draft happen immediately when entering a position (original behavior). The game is still fun because the user gets the best remaining picks. Let me revert to the simpler approach:
Now build:
Everything builds clean. Let me now do a thorough review of all the files to make sure the game flow is complete and polished. Let me check for edge cases:
- What if not enough players for AI draft? The fallback in
onDraftComplete handles that.
- What if user tries to pick when slots are full?
shakeCard animation.
- What if the keyboard number is out of range? The handler checks
availablePlayers[idx].
- The match generates all events upfront and reveals them as the clock ticks.
Let me also check that the cn utility is properly used:
The cn utility exists but I'm not using it - I'm using template literals directly. That's fine.
Let me now do one final quality pass. I want to make sure:
- The DICE animation is satisfying
- The particles work well
- The score system is clear
- The high scores persist and display correctly
Let me also look at a potential bug: when the user completes all positions and clicks "Start Match", we need to make sure the AI has drafted for all positions. The AI draft fires per position, but if the user quickly picks all players, the AI draft might still be in progress for the last position. Let me add a check:
The handleConfirm already handles AI draft not being done via fallback players. This is fine.
Let me also check that the fast-forward on Space key during intro phase works to skip the warm-up. Let me verify what happens - yes, speedUp checks phase === 'intro' and jumps to playing. Good.
Now one thing I want to fix: the useEffect for the AI draft has currentPos as a dependency. But the variable aiDrafting is in the dependency array - it should be fine since we only use it as a guard.
Actually, wait - there's a subtle issue with the AI draft effect. The effect uses teams in the closure but it's not listed as a dependency. teams is a prop and won't change. That's fine.
Let me now focus on polish. Let me add a few more things:
- The start screen should show high scores
- The dice should have more dramatic animation
Let me update the start screen to show high scores:
Now let me also make the dice rolling more dramatic. Let me update DiceRoller with better animation:
Build passes. Now let me think about what else the game needs to make it playable and polished end-to-end:
- ✅ Start screen with name entry
- ✅ Dice roll to get 3 random WC teams
- ✅ Player draft by position (GK → DEF → MID → FWD)
- ✅ AI draft from same pool
- ✅ Match simulation with live events, goals, particles, screen shake
- ✅ Game over with score calculation
- ✅ High scores persisted to localStorage
- ✅ Restart flow
Let me now test a few more edge cases and add final polish. Let me also add a formation display on the game over screen showing both teams.
Let me also add a "skip" option during the match intro to go straight to playing:
Files built: src/data/teams.ts, src/game/engine.ts, src/index.css, src/components/Particles.tsx, src/components/StartScreen.tsx, src/components/DiceRoller.tsx, src/components/PlayerDraft.tsx, src/components/MatchSim.tsx, src/components/GameOver.tsx, src/App.tsx, index.html, src/components/PitchFormation.tsx