Skip to content

AmmarHashlamoun/coexistence-card-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoExistence — Networked Multiplayer Card Game (Java)

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.

Overview

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.

Features

  • Server program that accepts and pairs clients for matches
  • Threaded server architecture using ConnectionThread for concurrent sessions
  • Game state logic fully encapsulated in GameState class
  • Clear separation of concerns: Player, Unit, and Deck handle game data
  • Command-based interface for local and remote play
  • TextUI class for terminal-based testing and local gameplay

Game Rules

  • 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

Gameplay Flow

  1. The server waits for two clients to connect.
  2. Each connection is passed to a new ConnectionThread.
  3. Each player receives their hand and takes turns making moves.
  4. The server parses commands, updates game state, and relays feedback.
  5. The game ends when a win condition is met, and the result is broadcast.

Technologies Used

  • Java (Java 11+)
  • Java Socket API
  • Java multithreading
  • Buffered I/O streams
  • Terminal-based UI for testing and gameplay

Testing & Debugging

A TextUI class is provided to simulate two-player games locally via terminal. This helps with debugging game logic without needing network connections.

Educational Purpose

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

Current Status

  • Core game logic is functional
  • Server-client networking is operational
  • Local terminal play is supported
  • GUI interface optional and not required

Getting Started

  1. Compile and run ThreadedServer.java
  2. Open two terminal clients and connect via nc localhost 1024
  3. Enter move commands or pass (e.g., BD, ps)
  4. Monitor output from both sides and game state transitions

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages