A real-time ball sorting puzzle game with competitive leaderboards, built with Node.js, WebSockets, and vanilla JavaScript.
- ๐ฎ Real-time WebSocket communication - Instant game state updates
- ๐ Global Leaderboard - Track top 5 high scores with player names
- ๐ค Player Profiles - Enter your name for leaderboard recognition
- ๐จ Dynamic level generation - Scales from 4x4 to 10x10 grids
- ๐ Dark/Light theme toggle - Persistent theme preference
- โฑ๏ธ Live statistics - Track level, moves, time, and cumulative score
- ๐ Restart functionality - Reset current level anytime
- ๐ฑ Responsive design - Optimized for desktop and mobile devices
- ๐ฏ Progressive difficulty - Levels get larger and more challenging
- ๐ Victory celebrations - Confetti animations and special messages
- ๐จ Accessibility - Emoji-based tokens for colorblind users
- ๐ฑ๏ธ Multiple input methods - Click, drag & drop, and touch support
- ๐ Endless gameplay - Game resets after level 10 for continuous play
- ๐พ Session persistence - Games save across browser sessions
- ๐ High score tracking - Personal bests preserved on leaderboard
- Click Method: Click a column to select it, then click another column to move the top token
- Drag & Drop: Drag the top token from one column and drop it on another column (desktop & mobile)
- Movement Rules: You can only move a token to an empty column or a column with available space
- Goal: Sort all tokens so each column contains only one type of emoji
- Level Progression: Complete levels to unlock larger grids (4ร4 โ 5ร5 โ 6ร6 โ etc.)
- Game Reset: After completing level 10, the game resets to level 1 with fresh scoring
- Scoring: Points accumulate across levels until game reset
# Clone the repository
git clone https://github.com/CyberSecDef/Chromastack.git
cd Chromastack
# Install dependencies
npm install
# Start the server
npm startThe game will be available at http://localhost:8016
Chromastack/
โโโ server.js # WebSocket server with leaderboard and session management
โโโ client.js # Client-side game logic, UI, and WebSocket handling
โโโ shared.js # Shared game state, rules, and level generation
โโโ index.html # Game HTML structure with modals and leaderboard
โโโ styles.css # Responsive styling with dark/light theme support
โโโ package.json # Node.js dependencies and scripts
โโโ assets/ # Game assets directory
- Backend: Node.js, Express, WebSocket (ws)
- Frontend: Vanilla JavaScript, HTML5, CSS3, HTML5 Drag & Drop API
- Communication: WebSocket for real-time bidirectional communication with message queuing
- Styling: CSS custom properties for theming, responsive design with flexbox
- Storage: localStorage for client-side persistence, in-memory server storage
- Security: Input validation, rate limiting, session management
- Levels 1-10: Progressive difficulty with cumulative scoring
- Level 1-2: 4x4 grid (3 colors, 1 empty column)
- Level 3-4: 5x5 grid (4 colors, 1 empty column)
- Level 5-6: 6x6 grid (5 colors, 1 empty column)
- Level 7-8: 7x7 grid (6 colors, 1 empty column)
- Level 9-10: 8x8 grid (7 colors, 1 empty column)
- Game Reset: After level 10 completion, game resets to level 1 with 0 points
- Endless Play: Continue playing indefinitely with fresh scoring each cycle
- Level Score: Calculated as
(totalTokens ร 10000) รท (moves ร 0.25 ร max(time, 1)) - Cumulative Score: Points accumulate across levels until game reset
- High Scores: Personal bests are tracked and displayed on leaderboard
- Reset Timing: Scores reset to 0 after level 10 completion
- Top 5 Display: Shows highest scores across all players
- Personal Bests: Only updates when player achieves new high score
- Player Names: Customizable player names for recognition
- Persistent: High scores survive server restarts and game resets
๐ ๐ ๐ซ ๐ฅฆ โญ ๐ ๐ ๐ ๐ โค๏ธ
- Desktop: Click-to-select or drag & drop
- Mobile: Touch gestures with drag support
- Accessibility: Emoji-based tokens work for colorblind users
npm run dev
# or
npm startPORT- Server port (default: 8016)
- Real-time Communication: WebSocket with automatic reconnection and message queuing
- Session Management: Persistent game state across browser sessions
- Responsive UI: Mobile-first design with touch optimization
- Performance: Efficient DOM updates and CSS animations
Key UI Elements:
- Status Bar: Level, moves, time, total score, and player name input
- Game Board: Dynamic grid that grows with level progression
- Leaderboard: Top 5 high scores with player names
- Control Buttons: Restart, theme toggle, and help
- Column Selection: Click or drag to select and move tokens
- Victory Modal: Shows level score with confetti celebration
- Game Reset: Special "Game Complete!" modal after level 10
- Mobile Support: Touch-optimized interface for phones and tablets
- High Score Tracking: Personal bests preserved across sessions
- Player Recognition: Custom names on leaderboard
- Real-time Updates: Leaderboard updates when new high scores achieved
join:{ sessionId, name }- Join game with session and player namemove:{ fromColumn, toColumn }- Move token between columnsnextLevel:{}- Progress to next levelrestart:{}- Reset current levelupdateName:{ name }- Update player namegetState:{}- Request current game state
gameState:{ ...gameData }- Full game state updatelevelComplete:{ level, moves, time, levelScore, totalScore, gameReset }- Level completion notificationleaderboard:[ { name, score, level }, ... ]- Top 5 leaderboard update
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly (WebSocket functionality, mobile responsiveness, scoring)
- Submit a pull request
MIT License - see LICENSE file for details

