This project implements a multiplayer text-based battle game server using Unix sockets. The game is inspired by Pokemon battles, where two players engage in combat until one player loses all hitpoints. Players can attack, use powerful moves, or send messages during the game.
- A demo video of the server running is available on YouTube.
- Watch the demo here: Video Demo
- Client Handling: Supports multiple clients connecting via
nc(netcat). - Matchmaking System: Pairs players dynamically based on availability.
- Battle Mechanics:
- Randomized hitpoints and power moves for each match.
- Regular and power attacks with different damage mechanics.
- Turn-based attacks and in-game messaging.
- Drop Handling: Detects client disconnections and announces winners.
- Concurrency: Uses
select()for non-blocking socket communication. - Port Selection: Allows defining the port number at compile time.
- Clone the repository:
git clone <repo_link>
- Compile the server using the Makefile:
make PORT=<your_port>
- The default port is set based on the student number convention (
5XXXX). - Example:
make PORT=53456
- The default port is set based on the student number convention (
- Run the server:
./battle
- Open a terminal and start the server:
./battle
- Connect clients using
nc:Example:stty -icanon nc <server_ip> <port>
nc cs.utm.utoronto.ca 53456
- Enter your name and wait for an opponent.
- Use the following commands during battle:
a- Regular attackp- Power move (if available)s- Say something to the opponent
- Players start each match with 20-30 HP and 1-3 power moves.
- Regular attacks deal 2-6 HP damage.
- Power moves have a 50% chance to miss, but deal 3x damage if successful.
- Players take turns attacking, and only the active player can speak.
- Players wait for a new opponent after a match ends.
This project includes additional features beyond the basic requirements:
- Strategic Gameplay Addition: Players can choose a special ability at the start of a match, such as increased dodge chance or extra power moves.
- Message Limit: Added a message limit by introducing a message counter attribute to the client struct. Each player's message count resets to 0 when they attack, preventing excessive messaging and encouraging balanced gameplay.
- If a player disconnects (
Ctrl+C), their opponent automatically wins. - The disconnected player is removed, and the server waits for new opponents.
- Use multiple
ncclients to test. - Run in noncanonical mode (
stty -icanon) for proper interaction. - Verify matchmaking and battle mechanics with various test cases.