An under 500 lines of code prototype Threads Siege made for a subject in uni, an arcade-style space defense game built with Java Swing. Players use their spaceship cannon to shoot down incoming alien enemies while avoiding letting too many enemies slip through.
Screenshot 1. Gameplay Screenshot (UI in Ukrainian)
- Multithreaded Mechanics: Each enemy and bullet runs independently on its thread, allowing real-time movement and interaction.
- Dynamic Difficulty Adjustment: The number of active enemies and their spawn rate automatically increase as the game progresses, based on the player's score and elapsed time.
- Collision-Based Scoring: Bullets destroy enemies on contact, incrementing the score while missed enemies contribute to the game-over counter.
- Limited Ammo: Players can have only three active bullets at a time, managed using a semaphore for concurrency control.
- Game State Feedback: The UI dynamically updates to reflect the player's score and missed enemies, with win/lose conditions displayed at the game end.
Ensure you have the following installed:
- Java 8 or higher
- Any Java IDE or a command-line terminal
-
Clone the repository:
git clone https://github.com/raccoon-hero/threads-siege.git cd threads-siege
-
Compile the project:
Using the terminal:javac ThreadsSiege.java
-
Run the game:
java ThreadsSiege
- Arrow Keys: Move your cannon left and right.
- Spacebar: Shoot bullets (limited to three active bullets at a time).
threads-siege/
├── assets/ # Assets for showcasing gameplay (e.g., screenshots)
├── ThreadsSiege.java # Main game file
└── README.md # Project Documentation (you’re here! :D)
- Thread Termination: Active threads (e.g., enemies and bullets) are not guaranteed to terminate when the game exits, which may lead to memory leaks or lingering processes.
- Concurrency Management: Shared resources like
enemies
andbullets
are manually synchronized, which could cause subtle bugs under certain conditions. - UI Scaling: Game objects do not resize dynamically when the window size is changed, resulting in potential layout issues.
- Repaint Performance: Under heavy load, the UI may experience performance drops due to frequent updates and rendering of multiple threads.
- Error Handling: Exceptions such as
InterruptedException
are caught but not logged, which may hinder debugging.
- Thread Management: Implement a proper cleanup mechanism for threads to ensure they terminate cleanly when the game ends.
- Improved Concurrency: Replace manual synchronization with safer concurrent collections like
ConcurrentLinkedQueue
for managing enemies and bullets. - Customizable Settings: Introduce configuration options for adjusting game parameters such as enemy speed, bullet speed, and spawn rates.
- Graphics Scaling: Add support for responsive scaling of game objects to adapt to window resizing.
- Performance Optimization: Profile and optimize repaint intervals to reduce lag during heavy gameplay.
- Logging System: Integrate basic logging to capture runtime exceptions and errors for debugging purposes.
- Fork this repository.
- Create a feature branch (
git checkout -b feature/amazing-feature
). - Commit your changes (
git commit -m 'Add some amazing feature'
). - Push to the branch (
git push origin feature/amazing-feature
). - Open a Pull Request.