This project is a modern implementation of the classic Snake Game using TypeScript. The game includes features such as a game board, a snake, food for the snake, and a scoring system. The game is built with object-oriented programming principles in mind, making the code modular and easy to maintain.
src/board.ts
: This file contains theBoard
class which handles the game board, game state, and game logic. It includes methods for starting and stopping the game, handling key presses, checking for collisions, and drawing the game elements on the board.src/food.ts
: This file contains theFood
class which handles the creation and placement of food on the game board.src/game.ts
: This file contains the main game logic, including the game loop and event listeners.src/snake.ts
: This file contains theSnake
class which handles the snake's behavior, including movement and growth.src/score.ts
: This file contains theScore
class which handles the game score, including updating and displaying the score.src/style.css
: This file contains all the styles for the game.src/index.html
: This is the main HTML file that displays the game.
- Open
index.html
in your browser. - Press the spacebar to start the game.
- Use the arrow keys to control the direction of the snake.
- The game ends when the snake hits the game board edge or its own body.
- The score is updated based on the length of the snake.
This project uses modern TypeScript features, including classes and private class fields. It is organized into modules for better code organization and maintainability.
This project is licensed under the terms of the MIT license.
Contributions are welcome! Please read the CODE_OF_CONDUCT.md for details on our code of conduct, and the process for submitting pull requests to us.