CoExistence is a two-player, turn-based card game implemented in Java. It supports both local terminal play and a full networked multiplayer mode using Java sockets and multithreading.
The game is a strategic variation of rock-paper-scissors. Each player controls a hand of unit cards and takes turns selecting attackers to eliminate the opponent’s units. The goal is to be the first player to reach 9 points or to have the most points after 5 rounds.
- Server program that accepts and pairs clients for matches
- Threaded server architecture using
ConnectionThreadfor concurrent sessions - Game state logic fully encapsulated in
GameStateclass - Clear separation of concerns:
Player,Unit, andDeckhandle game data - Command-based interface for local and remote play
- TextUI class for terminal-based testing and local gameplay
- Four unit types: Axe, Hammer, Sword, Arrow
- Combat logic:
- Axe defeats Hammer
- Hammer defeats Sword
- Sword defeats Axe
- Arrow defeats any unit but does not earn points
- Each player starts with 6 units
- Players alternate turns making moves or passing
- A round ends when both players pass
- The game ends when a player reaches 9 points or 5 rounds are completed
- The server waits for two clients to connect.
- Each connection is passed to a new
ConnectionThread. - Each player receives their hand and takes turns making moves.
- The server parses commands, updates game state, and relays feedback.
- The game ends when a win condition is met, and the result is broadcast.
- Java (Java 11+)
- Java Socket API
- Java multithreading
- Buffered I/O streams
- Terminal-based UI for testing and gameplay
A TextUI class is provided to simulate two-player games locally via terminal. This helps with debugging game logic without needing network connections.
Developed as part of a Computer Systems course to demonstrate:
- Socket-based network programming
- Concurrency and thread management
- Game state management and input validation
- Modular object-oriented programming in Java
- Core game logic is functional
- Server-client networking is operational
- Local terminal play is supported
- GUI interface optional and not required
- Compile and run
ThreadedServer.java - Open two terminal clients and connect via
nc localhost 1024 - Enter move commands or pass (e.g.,
BD,ps) - Monitor output from both sides and game state transitions