This project is a socket-based multiplayer game where players aim to select a number closest to two-thirds of the average of all players' choices in each round. The last remaining player wins the game.
- Each player starts with 5 points.
- In each round:
- Players choose an integer between 0 and 100.
- Choices are submitted to the game server within a given time frame.
- The winner(s) of the round is the player(s) whose choice is closest to two-thirds of the average of all submitted numbers.
- Players lose 1 point for each losing round.
- A player is eliminated when they run out of points.
- After each round, the following is announced:
- Round number
- Players still in the game
- Numbers chosen
- Remaining points for each player
- Round outcome (winners/losers)
- Eliminated players, if any
- The game is won by the last remaining player.
- Special Rule: In the final round with two players, if one chooses 0, the other player wins if their guess is greater than 0.
- Compile the Java files:
javac *.java
- Start the server:
java Server
- Start the client(s) in separate terminals:
java Client <Server IP Address> <Provide Port Here>
- Follow the instructions in the client terminal to join the game.
⚠️ NOTE: You can run the code on a server or an online VM and join the game using its IP address. Ensure that the necessary ports are open for inbound/outbound traffic.
⚠️ NOTE: The GUI is not fully implemented. Please use the terminal to access and play the game.
- Manages the game server, handles client connections, manages games and players, and updates the leaderboard.
- Represents a player, storing the player's name, points, and number selection.
- Manages game logic: adding/removing players, determining winners, deducting points, and eliminating players.
- Executes the game, broadcasts messages, determines outcomes, and manages game flow.
- Handles client connections and client-server communication.
- Manages player input for each round, ensuring a timely number of submissions.
- Manages the timeout for player input during each round, closing connections for players who fail to submit in time.
- The client application that connects to the server, allowing players to interact with the game.
- Generates and manages unique tickets for players to join the game.
The code includes thorough comments detailing the purpose and functionality of each class and method. It adheres to best practices in object-oriented programming and employs synchronization techniques to ensure thread safety.