A classic Tetris game implemented in React and TypeScript. This project showcases a basic implementation of the Tetris game mechanics, including piece movement, rotation, line clearing, and scoring.
- Piece Movement: Move pieces left, right, and down using arrow keys.
- Piece Rotation: Rotate pieces using the up arrow key.
- Line Clearing: Automatically clears full lines and updates the score.
- Game Over: Displays a "Game Over" screen with the final score and a button to restart the game.
- Responsive Design: Styled using Tailwind CSS for a clean and modern look.
The game integrates with Supabase to manage and display the top 10 scores. When the game ends and if the final score is high enough, the player can input their name to save the score. The top 10 scores are fetched from Supabase and displayed on the screen.
- Score Submission: Upon game over, players can submit their scores along with their name. The score is saved to a Supabase database table called
score
. - Score Display: The top 10 scores are fetched from the Supabase database and displayed on the screen.
-
Clone the Repository
git clone https://github.com/pnvdev/nextjs-tetris.git cd tetris-game
-
Install Dependencies
Ensure you have Node.js installed. Then, install the project dependencies:
pnpm install
-
Configure Supabase
Create a .env.local file in the root of the project and add your Supabase credentials:
NEXT_PUBLIC_SUPABASE_URL=your-supabase-url NEXT_PUBLIC_SUPABASE_KEY=your-supabase-key
Open
http://localhost:3000
in your browser to play the game. -
Run the Development Server
Start the development server to run the game:
pnpm dev
Open
http://localhost:3000
in your browser to play the game.
-
Arrow Keys:
- Left Arrow: Move the piece left.
- Right Arrow: Move the piece right.
- Down Arrow: Move the piece down faster.
- Up Arrow: Rotate the piece.
-
Play Again: After the game is over, click the "Play Again" button to restart the game.
- Code Style: Follow TypeScript and React best practices.
- Styling: Tailwind CSS is used for styling. Customize styles in
tailwind.config.js
if needed. - State Management: React's
useState
anduseEffect
hooks are used for managing game state and effects.
- Fork the repository.
- Create a new branch for your feature or fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Open a pull request with a description of your changes.
This project is licensed under the MIT License.
For any questions or feedback, please reach out to [email protected].