Programming Assignment 2: Multiplayer Game (Rock-Paper-Scissors)
Course Details
● Course Name: CSCI 4311/5311
● Assignment: Programming Assignment 2 (PA2)
1. Introduction
The purpose of this assignment was to implement a multiplayer game using
client-server architecture and socket programming. The chosen game was
Rock-Paper-Scissors, adhering to the following requirements:
● Establishing server-client communication for multiplayer gameplay.
● Implementing a multithreaded server to handle multiple clients simultaneously.
● Managing game logic and broadcasting results.
The program demonstrates a fully functional implementation of the required features.
2. Requirements and Implementation
Requirements
1. Use a client-server architecture.
2. Handle at least two clients (players) in a multiplayer environment.
3. Ensure the server is multithreaded to handle multiple connections
simultaneously.
4. Manage the game logic for Rock-Paper-Scissors.
5. Notify clients about the game result and shut down the server gracefully.
Implementation
1. Server:
● The server uses a multithreaded architecture (ExecutorService) to
handle two client connections.
● Manages game state, collects player choices, determines the winner, and
broadcasts the results.
2. Clients:
● Clients connect to the server, send their choices (rock, paper, or scissors),
and receive game results.
● Gracefully handle the "Game over" notification from the server.
3. Game Logic:
● The server determines the winner based on standard
Rock-Paper-Scissors rules:
● Rock beats Scissors.
● Scissors beat Paper.
● Paper beats Rock.
4. Shutdown Mechanism:
● The server shuts down automatically after one game, notifying both
players before termination.
3. Execution Steps
How to Run
1. Compile the server and client files:
javac Server.java Client.java
2. Start the server in a terminal:
java Server
3. Start two clients in separate terminals:
java Client and java Client
4. Enter choices (rock, paper, or scissors) for both players when prompted.
5. Observe the results and the server shutdown message.
4. Sample Outputs
Server Output
Client 1 Output (Example 1)
Client 2 Output (Example 1)
Client 1 Output (Example 2)
Client 2 Output (Example 2)
5. Features
● Multiplayer Gameplay: Two players connect to the server and play a game of
Rock-Paper scissors.
● Correct Game Logic: The server correctly determines the winner based on
standard rules.
● Graceful Shutdown: The server notifies clients before shutting down.
● Error-Free Execution: No unexpected errors or hanging connections.
6. Limitations
● The server supports only one game session. For extended gameplay, the server
would need enhancements to reset the game state after each round.
8. Conclusion
The implementation meets all requirements for PA2. The game is functional, and all
interactions between the server and clients occur as expected. The server handles
connections and game logic efficiently, ensuring a smooth multiplayer experience.