DEV Community

Ridham Khandar
Ridham Khandar

Posted on

How I built interactive game using Cursor and Claude sonnet 4

I will talk about how I built this NameTheCountries using Cursor Ai + Cluade Sonnet 4

I love to build random websites and stuff as a developer and I've always been fascinated by the potential of AI-powered development tools.
When I came across Cursor, I knew it that I am gonna build hell lot of stuff using this, So the first thing that I built was "Name The Countries" - a comprehensive geography learning game that exceeded my initial expectations.

The journey began with a simple prompt to Cursor AI: "Help me build a geography guessing game where users can identify countries on a map."

What impressed me immediately was how Claude understood not just the basic requirement, but anticipated the architectural needs:

// GameContext.tsx - Claude immediately suggested using React Context for state management
interface GameState {
  mode: GameMode;
  gameActive: boolean;
  startTime: number | null;
  score: number;
  guessedLocations: Set<string>;
  currentGuess: string;
  hints: number;
  // ... and much more
}
Enter fullscreen mode Exit fullscreen mode

Claude didn't just create a basic game loop but it architected a scalable context system that could handle multiple game modes, scoring, timing, and even prepared the foundation for multiplayer functionality that I hadn't even mentioned yet.

One of the most challenging aspects was implementing the interactive map with country highlighting. I asked Cursor to help me integrate Leaflet.js:

// GameMap.tsx - Claude created a sophisticated mapping component
const GameMap = () => {
  const { gameState, updateMapStyles } = useGame();

  useEffect(() => {
    if (gameState.locationData && gameState.gameActive) {
      updateMapStyles();
    }
  }, [gameState.guessedLocations, gameState.locationData]);

  // Dynamic country highlighting based on game state
  const getLocationStyle = useCallback((location: any) => {
    const isGuessed = gameState.guessedLocations.has(location.name);
    // Complex styling logic for different states
  }, [gameState.guessedLocations]);
};
Enter fullscreen mode Exit fullscreen mode

The most ambitious feature request I made was: "Add real-time multiplayer functionality where players can compete in the same game."

Claude didn't just add a simple multiplayer mode - it architected a complete real-time system:

// Firebase integration with sophisticated room management
const MultiplayerGame = memo(() => {
  const [roomData, setRoomData] = useState<any>(null);
  const [currentPlayer, setCurrentPlayer] = useState<any>(null);

  // Real-time room data subscription
  useEffect(() => {
    const unsubscribe = multiplayerService.subscribeToRoom(gameState.roomCode, (room) => {
      setRoomData(room);
      // Synchronized game state management
    });
    return () => unsubscribe?.();
  }, [gameState.roomCode]);

  // Synchronized timer across all players
  useEffect(() => {
    if (roomData?.gameStartTime && gameState.gameActive) {
      const syncedElapsed = Math.floor((Date.now() - roomData.gameStartTime) / 1000);
      // Complex synchronization logic
    }
  }, [roomData?.gameStartTime]);
});
Enter fullscreen mode Exit fullscreen mode

The AI handled:

  • Firebase Firestore real-time subscriptions
  • Synchronized game timers across players
  • Room management with join/leave functionality
  • Race condition handling
  • Player state synchronization
  • Winner determination logic

One of the most iterative parts of the development was UI refinement. I frequently gave feedback like:

"The navbar looks congested, can you make it cleaner?"

Claude would respond with thoughtful redesigns:

// From a cluttered navbar to a clean, organized header
const GameHeader = () => {
  return (
    <div className="w-full flex flex-col md:flex-row justify-between items-center gap-4 mb-6">
      <div className="flex items-center gap-6">
        <h1 className="text-3xl md:text-4xl font-bold text-blue-600 dark:text-blue-400">
          Name The Countries
        </h1>
        {/* Status indicators */}
      </div>

      <div className="flex flex-wrap items-center gap-3">
        {/* Game controls organized logically */}
      </div>
    </div>
  );
};
Enter fullscreen mode Exit fullscreen mode

Results and Impact

The final application exceeded my initial expectations:

  • Performance: Smooth gameplay across devices with optimized rendering
  • User Experience: Intuitive interface with professional polish
  • Scalability: Architecture ready for additional features and game modes
  • Code Quality: Well-structured, typed, and maintainable codebase

Lessons for AI-Assisted Development

Do's:

  1. Start with clear, specific requirements
  2. Iterate and refine based on testing
  3. Provide context about user experience goals
  4. Ask for explanations of complex implementations
  5. Test thoroughly and report specific issues

Don'ts:

  1. Don't try to specify everything upfront
  2. Don't accept solutions without understanding them
  3. Don't skip testing intermediate implementations
  4. Don't assume AI understands unstated requirements

You can check out the game here: NameTheCountries

I am up for feedback and suggestions to improve the game even further.

Top comments (3)

Collapse
 
kchdb14 profile image
Kchdb • Edited

Amazing work building an interactive game with Claude and custom cursor logic! When exploring game integration, I also experimented with 1win, which delivered impressively smooth UI response and fast feedback loops. It felt a bit like your game engine—light, reactive, and user‑centric. For anyone prototyping interactive elements, this platform offers solid case study material. The click-to-action responsiveness mimics game controls, and the overall UX design aligns well with what devs strive for: intuitive, fluid, and fun.

Collapse
 
dhiraj_mohata_729ab946cb8 profile image
Dhiraj Mohata

Crazy man, the era of vibe coding 😂

Collapse
 
rythm18 profile image
Ridham Khandar

lol yeahh

Some comments may only be visible to logged-in visitors. Sign in to view all comments.