Java Tetris is a simple implementation of the classic Tetris game written in Java. It provides a graphical user interface using Swing components and allows players to enjoy the addictive gameplay of arranging falling blocks to form complete lines.
During the third semester at Budapest University of Technology and Economics, as part of the requirements for the Programming 3 course, I undertook a homework project. For this project, I decided to create a simple implementation of the classic Tetris game, marking it as my first Java endeavor. Throughout the development process, I primarily relied on the course's presentation slides and supplemented my knowledge with help of the Internet.
- Colorful and intuitive graphical interface.
- Block shapes: I, J, L, O, S, T, Z.
- Controls:
- Arrow keys: Move the block left, right, down or rotate.
- Spacebar: Hard-drop block.
- Scoring:
- Points are earned for each completed line. The game use the classic Tetris point calculation.
- The game speed increases as the score increases.
- Leaderboard:
- Tracks and displays the top scores of players.
- Allows players to enter their names after a game over.
- Leaderboard data is saved, therefore your accomplishments will not disappear.
- Settings in menu:
- You can change the volumne of the game sounds and music.
- Settings in game:
- Pause
- Restart
- Mute
To run the Java Tetris game on your machine, follow these steps:
- Ensure you have Java Development Kit (JDK) installed.
- Clone the repository or download the source code.
- Open a command prompt or terminal window on your computer.
- Navigate to the src directory of the Java program. For example, if the program folder is located at C:\Projects\JavaTetris\src, you would use the following command in the command prompt:
cd C:\Projects\JavaTetris\src
- Once you are inside the src directory, compile the program by executing the following command:
This command will compile the Tetris.java file and generate the corresponding .class files.
javac -cp . com/mia_princz/tetris/Tetris.java
- After compiling the program, navigate one level up in the directory structure using the following command:
cd ..
- Now execute the following command to run the program:
This command will launch the Tetris class, which contains the main function, and run the Java program.
java -cp .;src;game_assets;game_sounds com.mia_princz.tetris.Tetris
- Launch the game using the instructions mentioned in the "Getting Started" section.
- The menu window will open. Click on the "Start Game" button.
- The menu window will close and game window will open, displaying the game grid.
- Use the arrow keys to move the falling block left, right, or down.
- Use the 'up' arrow to rotate the block.
- Press space to hard-drop the block.
- Try to arrange the falling blocks to form complete horizontal lines.
- When a line is completed, it will be cleared, and you will earn points.
- As you score more points, the game speed will increase.
- If the stack of blocks reaches the top of the grid, the game ends.
- After a game over, enter your name when prompted to save your score to the leaderboard.
- Click on the "Pause" button to pause the game or "Restart" button to restart the game at any time.
- Click on the "Mute" button to mute the game sounds and music, click on the "Unmute" button to turn back on the sounds and music.
- Clcik on the "Return to Menu" button to close game window and open the menu window.
This project is licensed under the MIT License. See the LICENSE file for more details.
Contributions to this project are welcome. If you find any issues or have ideas for improvements, feel free to open an issue or submit a pull request.
Please note that the images, music, and sounds used in this project may be subject to copyright and other intellectual property rights held by their respective owners. I do not claim ownership of these assets, and I have used them for demonstration purposes only. It's important to respect the rights of asset creators and obtain proper permissions or licenses before using their work in your own projects. I encourage you to replace these assets with your own or use assets that are properly licensed for your specific use case. If you are the creator or owner of any of the images, music, or sounds used in this project and would like them to be removed or credited differently, please contact me, and I will promptly address your concerns. Thank you for understanding and respecting the rights of asset creators.