Skip to content

TitouanPastor/RivalsForCatan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rivals of Catan - Digital Implementation

A Java implementation of the two-player card game Rivals for Catan, featuring network play, extensible architecture, and comprehensive game mechanics.

Java Tests Architecture

About the Game

Rivals for Catan is a card-based strategy game where two players build principalities by constructing settlements, producing resources, and expanding territories. First player to reach 7 Victory Points wins.

This digital implementation includes the complete base game (94 cards), network multiplayer, automated bot players, and an extensible architecture for adding expansions.


Features

Gameplay:

  • Complete base game implementation (94 cards)
  • Turn-based phases: Roll, Action, Replenish
  • Resource production and management
  • Card building with costs and placement rules
  • Event system and card effects
  • Victory condition (7 VP)

Technical:

  • Network multiplayer (local/remote via sockets)
  • Bot players for testing
  • Extensible architecture (Strategy, Factory, Observer patterns)
  • 33 acceptance tests covering all requirements
  • Clean separation of concerns

Architecture

The project follows SOLID principles and implements several design patterns:

src/main/java/com/rivalofcatan/
├── cards/          # Card models and effects (Strategy pattern)
├── events/         # Domain events
├── hooks/          # Card interactions (Observer pattern)
├── model/          # Game logic and rules
├── player/         # Player state management (Facade pattern)
├── builder/        # Card creation (Factory pattern)
└── network/        # Communication layer (Strategy pattern)

Key Patterns: Strategy, Factory, Observer, Facade
Documentation: See DEVELOPER_GUIDE.md


Getting Started

Prerequisites

  • Java 17 or higher
  • Gson library (included in lib/gson.jar)

Build

IntelliJ IDEA (Recommended):

  1. Open project in IntelliJ IDEA
  2. Project will auto-compile
  3. Run ServerMain.java (right-click → Run)

Manual Compilation:

Windows (PowerShell/CMD):

mkdir target
Get-ChildItem -Path src\main\java -Filter *.java -Recurse | ForEach-Object { $_.FullName } | Out-File -FilePath sources.txt -Encoding ascii
javac -cp "lib\gson.jar" -d target "@sources.txt"

Linux/macOS:

mkdir -p target
find src/main/java -name "*.java" > sources.txt
javac -cp "lib/gson.jar" -d target @sources.txt

Note: This compiles all .java files including classes loaded via reflection (hooks, placement requirements).

Run

Network Play - Option 1 (2 terminals): Server hosts the game AND plays locally (using --player flag) + 1 remote client.

Terminal 1 - Server with local player (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.server.ServerMain --player

Terminal 1 - Server with local player (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.server.ServerMain --player

Terminal 2 - Remote client (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Terminal 2 - Remote client (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Network Play - Option 2 (3 terminals): Server ONLY hosts the game (no --player flag) + 2 remote clients.

Terminal 1 - Server (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.server.ServerMain

Terminal 1 - Server (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.server.ServerMain

Terminal 2 and 3 - Remote clients (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Terminal 2 and 3 - Remote clients (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Bot Testing (Local Bot - server-side):

Terminal 1 - Server with local bot (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.server.ServerMain --bot

Terminal 1 - Server with local bot (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.server.ServerMain --bot

Terminal 2 - Human player (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Terminal 2 - Human player (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Bot Testing (Remote Bot - client-side):

Terminal 1 - Server (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.server.ServerMain

Terminal 1 - Server (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.server.ServerMain

Terminal 2 - Human player (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Terminal 2 - Human player (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.client.RemoteClientMain localhost 8080

Terminal 3 - Remote bot (Windows):

java -cp "target;lib\gson.jar;src\main\resources" com.rivalforcatan.network.client.RemoteBotMain localhost 8080

Terminal 3 - Remote bot (Linux/macOS):

java -cp "target:lib/gson.jar:src/main/resources" com.rivalforcatan.network.client.RemoteBotMain localhost 8080

Server Flags:

  • --player - Local human player
  • --bot - Automated bot player
  • --port <num> - Custom port (default: 8080)

Note: Windows uses ; as classpath separator, Linux/macOS use :

Tests

Run acceptance tests in IntelliJ: Right-click acceptance/ package → Run Tests

Test Coverage: 33 tests across 5 requirements (network play, card composition, initial draw, turn sequence, victory condition)


Project Structure

RivalsOfCatan/
├── src/main/java/com/rivalofcatan/    # Source code
│   ├── cards/                         # Card models and effects
│   ├── events/                        # Domain events
│   ├── hooks/                         # Card interactions
│   ├── model/                         # Game logic
│   ├── player/                        # Player state
│   ├── builder/                       # Card factory
│   └── network/                       # Communication
├── src/main/resources/                # Card data (JSON)
├── src/test/java/                     # 33 acceptance tests
└── DEVELOPER_GUIDE.md                 # Extension guide

Documentation


Technologies

  • Java 17
  • JUnit 5 (Testing)
  • Gson (JSON parsing)

License

Academic project. Game "Rivals for Catan" owned by Catan GmbH/Kosmos.

Contact

Titouan Pastor
Luleå University of Technology
GitHub Repository

About

RivalForCatan card game Java implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages