10 Classic Games Recreated in JavaScript
May 17th, 2022 | By Ejiro Thankgod | 12 min read
Classic games like Pong, Tetris, and Pac-Man remain ever-present because their gameplay is addictive and uncomplicated. Reverse engineering these games with JavaScript is not only retrospective but can also become a handy teaching tool when it comes to web development. Because JavaScript is browser-based and has libraries like HTML5 Canvas and p5.js available, developers can create interactive, web-based games.
In this article, we'll cover ten evergreen games (and two special extras) that can be recreated with JavaScript, explaining their mechanics, implementation strategies, and pedagogical value. Each of these sections references a GitHub repository of sample code from which developers can start.
Why Recreate Classic Games in JavaScript?
Building classic games in JavaScript sharpens skills such as game loop design, collision detection, and state management. These projects are accessible, running directly in browsers without installation, and they offer insights into game design principles that shaped modern gaming. Additionally, protecting your JavaScript code is crucial when sharing games online, and tools like Jscrambler can safeguard your work from theft or tampering.
1. Pong
Pong (1972) is a classic game where you volley a ball back and forth using paddles and score points. Mathematically, what makes Pong elegant is that the movement of the ball is just velocity algebra, collision detection with paddles is fast boundary checks, and points are just increment operations. And within that elegance is the foundation of game development: game loop, entity updates, and rendering cycles that form the basis of all game engines.
Key Features: Real-time paddle movement, ball physics, score tracking.
JavaScript Implementation: Use HTML5 Canvas to render paddles and the ball. Implement a game loop with requestAnimationFrame for smooth updates. Handle keyboard inputs (e.g., arrow keys) for paddle control and use basic collision detection for ball bounces.
Learning Focus: Event listeners, game loops, basic physics.
GitHub Repository: Pong JavaScript Code
2. Snake
Snake (1970s) puts students up against the challenge of navigating a growing snake to eat while steering clear of crashes. Snake takes the simple 'don't run into yourself' idea and turns it into a fun spatial awareness and forward-thinking test. From a programming standpoint, it is a great introduction to dynamic arrays and movement based on a grid.
Key Features: Grid-based movement, snake growth, game-over conditions.
JavaScript Implementation: Render a grid on Canvas, represent the snake as an array of coordinates, and update positions via keyboard input. Randomly place food and extend the snake upon eating.
Learning Focus: Array manipulation, input handling, and collision detection.
GitHub Repository: Snake JavaScript Code
3. Tetris
Tetris (1984) is a puzzle game where falling tetrominos are stacked and cleared to eliminate lines. Rotation of the tetromino pieces involves high-level transformation matrices, and clearing lines involves efficient array manipulation. Increasing the speed of the game results in a natural escalation of difficulty that maintains the player within the 'flow state'—engaged yet not frustrated.
Key Features: Block rotation, line clearing, and increasing speed.
JavaScript Implementation: Use a 2D array for the game grid, store tetromino shapes as matrices, and implement rotation logic. Use setInterval for timed block drops, accelerating over time.
Learning Focus: Matrix operations, timing functions, state management.
GitHub Repository: Tetris JavaScript Code
4. Space Invaders
Space Invaders (1978) involves shooting aliens that come downwards in waves before they fall below. It creates intrinsic tension with the pattern of movement of the invaders: shifting sideways and then falling downwards. It creates an emergent difficulty curve by itself without explicit programmatic instructions.
Key Features: Player shooting, enemy movement patterns, barriers.
JavaScript Implementation: Render sprites on Canvas, move enemies in a grid pattern, and manage player projectiles. Add simple AI for enemies to fire back.
Learning Focus: Sprite rendering, projectile mechanics, enemy AI.
GitHub Repository: Space Invaders JavaScript Code
5. Pac-Man
Pac-Man (1980) involves navigating mazes, munching dots, and avoiding ghosts, with their role reversed when they eat power pellets. This is one of the lovely examples of simple rules generating complex behavior of game AI. Blinky is a direct pursuer, Pinky points ahead of Pac-Man, Inky uses relative positions, and Clyde alternates between attack and defensive strategies.
Key Features: Maze generation, ghost AI, power-up mechanics.
JavaScript Implementation: Create a tile-based maze with a 2D array. Use simple pathfinding (e.g., rule-based or A*) for ghost movement. Render sprites for Pac-Man and ghosts, with collision detection for dots and power-ups.
Learning Focus: Pathfinding algorithms, sprite animation.
GitHub Repository: Pac-Man JavaScript Code
6. Breakout
Breakout (1976) challenges players to destroy bricks using a ball and paddle. The ball's interaction with different surfaces requires sophisticated collision response calculations. Bricks disappear upon contact, but paddle collisions must modify the trajectory based on the contact point and paddle movement.
Key Features: Ball trajectory, brick destruction, paddle control.
JavaScript Implementation: Use Canvas for rendering, calculate ball angles for bounces, and remove bricks on collision. Add multiple levels with varied brick layouts.
Learning Focus: Physics simulation, level design.
GitHub Repository: Breakout JavaScript Code
7. Minesweeper
Minesweeper (1989) involves uncovering safe tiles while avoiding hidden mines, guided by number clues. The core flood-fill algorithm, which reveals empty cells, demonstrates recursive programming beautifully—when a cell with zero adjacent mines is clicked, all connected empty cells should automatically reveal themselves. This creates the satisfying chain reactions that make Minesweeper addictive.
Key Features: Random mine placement, number clues, flagging system.
JavaScript Implementation: Build a grid with DOM elements or Canvas. Randomly place mines, calculate adjacent numbers, and handle click events for revealing tiles and right-clicks for flagging.
Learning Focus: Recursive algorithms, DOM interaction.
GitHub Repository: Minesweeper JavaScript Code
8. Asteroids
Asteroids (1979) has players piloting a ship to destroy asteroids while avoiding collisions. The ship accelerates in the direction it's facing, but momentum carries it forward regardless of its current orientation. This creates a unique movement challenge that requires players to consider physics rather than relying solely on simple directional input.
Key Features: Ship rotation, thrust mechanics, asteroid fragmentation.
JavaScript Implementation: Use vector math for ship movement and rotation. Render asteroids as polygons and split them on impact. Implement screen wrap-around for seamless movement.
Learning Focus: Trigonometry, dynamic object management.
GitHub Repository: Asteroids JavaScript Code
9. Tic-Tac-Toe
Tic-Tac-Toe is a game of strategy where X and O are placed within a 3x3 table by players to achieve alignment of three symbols. It is beautiful because the state space is limited to 362,880 possible game positions. It is ideal software to implement your first game AI. It employs the minimax algorithm, which guarantees optimal play, and serves as a great introduction to game theory and recursive thinking.
Key Features: Turn-based play, win condition checking, and an AI opponent.
JavaScript Implementation: Use DOM elements for the grid and click events for moves. Implement a minimax algorithm for an unbeatable AI opponent.
Learning Focus: Game tree logic, basic AI.
GitHub Repository: Tic-Tac-Toe JavaScript Code
10. Frogger
Frogger (1981) involves crossing roads and rivers while avoiding obstacles like cars and logs. Each lane operates independently with different speeds and patterns, yet players must coordinate movement across all layers. The river section adds complexity by making logs into moving platforms rather than obstacles.
Key Features: Moving obstacles, timed jumps, and a live system.
JavaScript Implementation: Render sprites on Canvas, move obstacles in patterns, and handle player jumps with keyboard input. Track lives and reset on collisions.
Learning Focus: Animation timing, collision detection.
GitHub Repository: Frogger JavaScript Code
Bonus Game: Chess
Chess (6th century; modern rules established by the 15th century) is a strategic board game in which players move pieces to checkmate their opponent’s king. Chess represents the pinnacle of strategic board games, with rules that have remained virtually unchanged for over 1500 years. From a programming perspective, it's an extraordinary challenge that combines complex rule validation, sophisticated AI implementation, and elegant user interface design.
Key Features: Turn-based movement, piece-specific rules, check/checkmate detection.
JavaScript Implementation: Use a 2D array to represent the 8x8 board, with objects for each piece’s position and type. Implement legal move validation and checkmate detection. Render the board using Canvas or DOM, supporting both mouse and touch input for moves.
Learning Focus: Complex state management, rule-based logic, AI for single-player.
GitHub Repository: Chess JavaScript Code
Bonus Game: Mortal Kombat
Mortal Kombat (1992) is a fighting game in which two players battle each other using attacks until one’s health is depleted. The fighting game genre demands precision, impossible in other game types. Every frame matters. Attacks have startup frames, active frames, and recovery frames that must be perfectly timed. Input buffering allows players to enter complex combinations while maintaining responsive controls.
Key Features: Player movement, attacks, health bars, and win conditions.
JavaScript Implementation: Use Canvas to render two characters with health bars. Implement movement (left/right, jump) and attack mechanics with keyboard (e.g., A/D/W/S, Arrow keys) or touch controls. Detect collisions for attacks and update health.
Learning Focus: Real-time input handling, collision detection, animation.
GitHub Repository: Mortal Kombat JavaScript Code
Bonus Game: Super Mario Bros
Super Mario Bros. (1985) is a platformer where players navigate Mario through levels, jumping on enemies and collecting items. Super Mario Bros didn't just define the platformer genre—it perfected it. Nintendo's masterpiece established gameplay conventions that remain standard today while introducing level design principles that transformed interactive entertainment into an art form.
Key Features: Platform physics, enemy AI, collectibles, and level progression.
JavaScript Implementation: Use Canvas for side-scrolling levels with tiles for platforms and enemies. Implement physics for jumping and gravity, and handle collisions with enemies and items: support keyboard or touch controls for movement and jumping.
Learning Focus: Platformer physics, tile-based rendering, scrolling levels.
GitHub Repository: Super Mario JavaScript Code
Conclusion
These thirteen games span difficulty from very simple input handling up to complex AI and are suited for developers of all experience levels.
However, when making your games available online, you must protect your JavaScript code. Products like Jscrambler provide powerful client protection that thwarts reverse engineering of your game logic, code lifting or theft, and unauthorized modifications. Using Jscrambler’s obfuscation and run-time protection features, you can securely protect your games while making them globally available.
Jscrambler
The leader in client-side Web security. With Jscrambler, JavaScript applications become self-defensive and capable of detecting and blocking client-side attacks like Magecart.
View All ArticlesMust read next
12 Useful JavaScript Newsletters
With so much happening in the JavaScript ecosystem, it's not easy to stay on top of things. Here are 12 newsletters to bring the best news straight to your inbox.
August 5, 2025 | By Abigail Amadi | 10 min read
15 Best Blogs To Follow About JavaScript
Here goes a list with 15 blogs about Javascript you should start following to become a master.
June 9, 2016 | By Jscrambler | 4 min read