A simple Java card game project created originally for my second year university module Software Design Patterns and later improved upon, demonstrating object-oriented programming and design patterns with a graphical interface.
- Fully object-oriented architecture
- GUI implemented with Java Swing
- Uses Strategy, Decorator, Factory, and Observer patterns
- Easily extensible for new card types and effects
- Strategy: Card attack behaviour (direct, beast-vs-beast, etc).
- Decorator: Temporary effects like buffs or debuffs on cards.
- Factory: Creation of cards and decks.
- Observer: GUI updates when game state changes.
PocketBeasts is a two-player, turn-based card game. Each player controls a deck of beast cards and battles to reduce the opponent's health to zero.
- Start of Game:
Each player draws an initial hand from their deck. Players take turns. - Turn Structure:
On your turn, you:- Gain mana (used to play cards).
- Draw a card from your deck.
- Play beast cards from your hand onto the battlefield, spending mana.
- Attack with beasts:
- Some beasts can attack directly (target the enemy player).
- Others engage in beast-vs-beast combat.
- End your turn to pass play to your opponent.
- Attacking:
- Each beast can attack once per turn, following its strategy (direct or beast attack).
- Direct attacks damage the opponent's health.
- Beast-vs-beast attacks can defeat opponent beasts and move them to the graveyard.
Ashen Lamb
- Class: Direct Attacker
- Mana: 2 | Attack: 1 | Health: 3
- Description: Sneaky low-attack, high-health direct attacker
Aqua Serpent
- Class: Beast Attacker
- Mana: 3 | Attack: 2 | Health: 5
- Description: Tanky water-based defender
Moss Golem
- Class: Beast Attacker
- Mana: 3 | Attack: 2 | Health: 4
- Description: Nature-based balanced tank
Fire Whelp
- Class: Direct Attacker
- Mana: 3 | Attack: 4 | Health: 3
- Description: High-damage fire-based direct attacker
Thunder Hawk
- Class: Direct Attacker
- Mana: 2 | Attack: 3 | Health: 2
- Description: Fast flying direct attacker
Frost Lynx
- Class: Beast Attacker
- Mana: 2 | Attack: 3 | Health: 2
- Description: Fast ice-based attacker
Stone Rhino
- Class: Beast Attacker
- Mana: 4 | Attack: 3 | Health: 6
- Description: Heavy tank with massive health
Shadow Bat
- Class: Beast Attacker
- Mana: 1 | Attack: 2 | Health: 1
- Description: Glass cannon - cheap with decent attack but fragile
Sun Sprite
- Class: Direct Attacker
- Mana: 2 | Attack: 2 | Health: 3
- Description: Light-based balanced direct attacker
Wind Sprite
- Class: Beast Attacker
- Mana: 1 | Attack: 1 | Health: 2
- Description: Cheap, fast early-game beast
- The game ends when either player's health drops to zero or below.
- The player with remaining health wins.
- If both players lose all health simultaneously or run out of resources (deck, hand, and in-play beasts), the game ends in a draw or by highest remaining health.
This application has been refactored and improved since its initial implementation in several ways:
- Design patterns have been applied throughout: The game logic is separated from the GUI using the Observer pattern, card behaviors use Strategy, and new cards can be created using Factory.
- Code modularity: Classes have been split into logical packages (model, controller, patterns, gui) for maintainability.
- Extensibility: New card types and attack strategies can easily be added without major rewrites.
- GUI improvements: The user interface updates automatically with game state changes, making the game flow intuitive and interactive.
- Robust end-game handling: The game now properly detects all win/loss/draw conditions.
- Cleaner, more readable code: The codebase is more modular and easier to understand.
- Open the project in your Java IDE.
- Run
Main.javato start the GUI game.
- JUnit tests are in the
testfolder.