Dragons' Dice Duel is a simple turn-based game implementation inspired by the tumultuous conflict known as the Dance of the Dragons from the House of the Dragon series. This project serves as a practical example of using gRPC (Google Remote Procedure Call) in Java, demonstrating how to handle communication between game clients and the server.
In the turbulent times of the Dance of the Dragons, House Targaryen is torn asunder by bitter familial feuds and political intrigue. The realm stands divided between two powerful factions:
Players take on the roles of these factions in a dice-rolling game, where each roll represents a strategic maneuver or diplomatic victory aimed at gaining support from influential lords and allies across Westeros.
To get started with Dragons' Dice Duel, follow these steps to set up and run the server and client. This guide assumes you have Java 11 or higher, Maven or Gradle for dependency management, and the gRPC and Protobuf tools installed.
First, clone the repository to your local machine:
git clone <repository-url> cd dragons-dice-duel
Ensure you have Maven installed. Then, build the project using the following command:
mvn clean install
The server listens for incoming gRPC requests and handles game logic. To start the server:
mvn exec:java -Dexec.mainClass="io.github.mojtabaj.data.DragonsDiceDuelServer"
By default, the server will run on port 6565. Ensure no other application is using this port.
The client interacts with the server, sending game requests and receiving responses. To run the client:
mvn exec:java -Dexec.mainClass="io.github.mojtabaj.data.DragonsDiceDuelClient"
The client will connect to the server, send join requests, and simulate dice rolls.
If you need to change the server address or port, update the DragonsDiceDuelClient
class. Modify the ManagedChannelBuilder
configuration to match your server settings:
ManagedChannel channel = ManagedChannelBuilder
.forAddress("localhost", 6565)
.usePlaintext()
.build();
Replace "localhost"
and 6565
with the appropriate server address and port if necessary.
The .proto
file defines the data structures and service contract used in this project.
Faction
: Enum representing the two factions in the game.PlayerData
: Message containing details about a player.GameData
: Message containing game state information and the winner.DiceData
: Message representing a dice roll and the player who rolled it.GameRequest
: Message used to send requests to the server (join game or roll dice).GameResponse
: Message used to send responses from the server (player joined, turn info, dice roll result, game result).DragonsDiceDuel
Service:
PlayGame
: A bidirectional streaming RPC that allows clients to send GameRequest
messages and receive GameResponse
messages.