A classic tank battle game implemented in Java using Swing framework.
- Java Development Kit (JDK): Version 8 or higher
- IDE: NetBeans IDE (recommended)
- Java Runtime: Properly configured within NetBeans
To launch the game:
- Navigate to
/src/main/Start.java - Execute the file using the Run command
- Single Player: Battle against AI-controlled tanks
- Two Player: Local multiplayer mode
Eliminate all enemy tanks while protecting your base to achieve victory.
The graphics engine utilizes pre-rendered sprite images for tank animations, including movement in four directions. All visual assets (tanks, walls, rivers, base) are stored in the /image directory.
The rendering system continuously redraws sprites based on the FRESHTIME parameter:
- Higher FRESHTIME: Faster tank movement and smoother animation
- Lower FRESHTIME: Slower gameplay with reduced frame rate
All graphics-related code is located in the /frame directory, which handles:
- Game interface creation and window management
- Size and speed configuration
- Keyboard input processing (
KeyEventhandling) - Object movement function calls
- Screen rendering operations
The game employs an object-oriented approach with distinct classes for each game entity:
- Map: Game environment and terrain
- Bullet: Projectile mechanics
- Tank: Player-controlled vehicles
- Boom: Explosion effects
- Bot Tank: AI-controlled enemies (inherits from Tank class)
Tank properties are configurable through the following parameters:
private boolean attackCoolDown = true; // Attack cooling mechanism
private int attackCoolDownTime = 500; // Attack cooldown in milliseconds
protected boolean hasBullet; // Bullet existence check to prevent rapid fire
private int life; // Tank health/livesBot tanks feature autonomous movement using randomized direction selection:
private Direction randomDirection() {
Direction[] dirs = Direction.values(); // Get direction enumeration values
Direction oldDir = dir;
Direction newDir = dirs[random.nextInt(4)];
if (oldDir == newDir || newDir == Direction.UP) {
// Re-randomize if same direction or moving up
return dirs[random.nextInt(4)];
}
return newDir;
}Audio assets are organized in the /audio directory, containing:
- Background music tracks
- Sound effects for game events
The utility classes handle loading and playing audio files during gameplay.
The codebase is thoroughly commented for educational purposes. Key components include:
- Graphics Layer: Visual rendering and user interface
- Game Logic: Core mechanics and rules
- Audio System: Sound management
- Utility Classes: Helper functions for asset loading
This project serves as a learning resource for Java game development. Feel free to explore the code comments for detailed implementation explanations.
This project is available for educational and personal use.

