Organized by CP Squad in association with HacktoberFest
Welcome to the 2048 Game project! This is a beginner-friendly open source contribution opportunity where you'll build the classic 2048 puzzle game using vanilla HTML, CSS, and JavaScript.
- Project Overview
- Features to Implement
- Technical Requirements
- Getting Started
- Project Structure
- Implementation Guidelines
- Contribution Workflow
- Code Standards
- Submission Checklist
- Resources
- Support
Build a fully functional 2048 game with a clean, modern interface that supports both light and dark themes. The game should be responsive, accessible, and provide a smooth user experience.
Difficulty Level: Beginner to Intermediate
Tech Stack: HTML5, CSS3, Vanilla JavaScript (No frameworks or libraries)
- 4x4 game grid
- Tile generation (2 or 4) at random empty positions
- Arrow key controls (Up, Down, Left, Right)
- Tile merging logic (same numbers combine)
- Score tracking and display
- Win condition (reaching 2048 tile)
- Game over detection (no valid moves remaining)
- "New Game" button to restart
- Smooth tile animations for movements and merges
- Light theme (default)
- Dark theme
- Theme toggle button
- Persistent theme preference (saved in browser)
- Smooth theme transition animations
- Best score tracking (high score)
- "Continue" option after winning
- Undo last move functionality
- Mobile touch/swipe support
- Sound effects (mute/unmute option)
- Different board sizes (3x3, 5x5)
- Pure HTML, CSS, JavaScript only - No frameworks, libraries, or external dependencies
- Single page application - All code in one HTML file or separate files (index.html, style.css, script.js)
- Responsive design - Must work on desktop, tablet, and mobile devices
- Cross-browser compatibility - Test on Chrome, Firefox, Safari, and Edge
- No external APIs or CDNs - All code must be self-contained
2048-game/
│
├── index.html # Main HTML file
├── style.css # Stylesheet with light/dark themes
├── script.js # Game logic and functionality
└── README.md # Project documentation
- Basic knowledge of HTML, CSS, and JavaScript
- A code editor (VS Code, Sublime Text, etc.)
- Git installed on your machine
- A GitHub account
-
Fork the Repository
# Click the 'Fork' button on the repository page -
Clone Your Fork
git clone https://github.com/YOUR_USERNAME/REPO_NAME.git cd REPO_NAME/2048-game -
Create a New Branch
git checkout -b feature/your-feature-name # Example: git checkout -b feature/dark-theme -
Start Coding!
- Open
index.htmlin your browser - Make changes and refresh to see updates
- Open
- Semantic HTML5 structure
- Game container with grid cells
- Score display area
- Control buttons (New Game, Theme Toggle)
- Meta tags for responsiveness
- CSS Grid or Flexbox for layout
- CSS custom properties (variables) for theming
- Smooth animations using CSS transitions
- Media queries for responsiveness
- Light theme styles (default)
- Dark theme styles (with
.dark-themeclass)
- Game state management
- Grid initialization
- Tile movement logic
- Merge calculation
- Score tracking
- Event listeners (keyboard, buttons)
- Theme toggle functionality
- Local storage for persistence
Grid Representation
// Use a 2D array to represent the grid
let grid = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
];Movement Algorithm
- Filter out zeros from the row/column
- Merge adjacent equal values
- Fill remaining positions with zeros
- Update the grid and UI
Win/Loss Conditions
- Win: Any tile reaches 2048
- Loss: No empty cells AND no adjacent tiles with same value
CSS Variables Approach
:root {
--bg-color: #faf8ef;
--text-color: #776e65;
--grid-bg: #bbada0;
/* ... more variables */
}
.dark-theme {
--bg-color: #1a1a1a;
--text-color: #f0f0f0;
--grid-bg: #2c2c2c;
/* ... dark theme overrides */
}Theme Toggle
- Use JavaScript to add/remove
dark-themeclass from body - Save preference in
localStorage - Apply saved theme on page load
- Tile appearance: scale or fade-in effect
- Tile movement: smooth position transitions
- Tile merge: pop or pulse animation
- Use CSS
transitionand@keyframes
-
Choose a Feature
- Check the Issues tab for open tasks
- Comment on an issue to claim it
- Wait for assignment before starting work
-
Write Code
- Follow the code standards below
- Test thoroughly in multiple browsers
- Ensure responsive design works
-
Commit Your Changes
git add . git commit -m "Add: dark theme implementation"
-
Push to Your Fork
git push origin feature/your-feature-name
-
Create a Pull Request
- Go to the original repository
- Click "New Pull Request"
- Select your branch
- Fill in the PR template with details
- Link the related issue (e.g., "Closes #5")
-
Address Review Comments
- Respond to feedback
- Make requested changes
- Push updates to the same branch
- Use semantic tags (
<header>,<main>,<section>) - Include proper ARIA labels for accessibility
- Validate using W3C Validator
- Use meaningful class names (BEM methodology preferred)
- Group related properties together
- Add comments for complex sections
- Maintain consistent indentation (2 spaces)
- Avoid
!importantunless absolutely necessary
- Use
constandletinstead ofvar - Write descriptive variable and function names
- Add comments for complex logic
- Use ES6+ features (arrow functions, template literals)
- Handle errors gracefully
- No
console.log()in final submission (or use conditionally)
// Variables: camelCase
let currentScore = 0;
// Functions: camelCase with verb
function initializeGame() { }
// Constants: UPPER_SNAKE_CASE
const GRID_SIZE = 4;
// Classes: PascalCase
class GameManager { }Before submitting your PR, ensure:
- Code runs without errors in console
- Game logic works correctly (test all movements)
- Both themes work properly
- Theme preference persists on reload
- Responsive on mobile, tablet, and desktop
- Tested on at least 2 different browsers
- Code is well-commented
- No unused code or files
- Follows the code standards
- Git history is clean (meaningful commit messages)
- Original 2048 Game - Play to understand the mechanics
- 2048 Game Rules - Wikipedia explanation
- Can I Use - Browser compatibility checker
- CSS Validator
- JSHint - JavaScript code quality tool
- Stuck on logic? Reach out to other contributors
- Found a bug? Create an issue with steps to reproduce
- Have questions? Reach out to the maintainers:
- Email: [email protected]
- Or contact Bhumi Shah (6352281640) or Priyanshi Gajiwala (70167 55944)
- Be respectful and inclusive
- Help other contributors when possible
- Ask questions - there are no dumb questions!
All contributors will be:
- Listed in the project README
- Mentioned in CP Squad's social media announcements
This project is licensed under the MIT License - see the VIEW LICENSE file for details.
We're excited to have you contribute to this project! Remember, every expert was once a beginner. Don't hesitate to ask questions and learn along the way.
Organized with ❤️ by CP Squad
Last Updated: October 2025