…
|
||
---|---|---|
.. | ||
AdventureClient | ||
AdventureGrainInterfaces | ||
AdventureGrains | ||
AdventureServer | ||
assets | ||
Adventure.sln | ||
Directory.Build.props | ||
Directory.Packages.props | ||
README.md |
README.md
languages | products | page_type | name | urlFragment | description | |||
---|---|---|---|---|---|---|---|---|
|
|
sample | Orleans Text Adventure Game | orleans-text-adventure-game | An example of a text adventure game written in C# using Orleans. |
Orleans Text Adventure Game
Before there were graphical user interfaces, before the era of game consoles and massive-multiplayer games, there were VT100 terminals and there was Colossal Cave Adventure, Zork, and Microsoft Adventure. Possibly lame by today's standards, back then it was a magical world of monsters, chirping birds, and things you could pick up. It's the inspiration for this sample.
Demonstrates
- How to structure an application (in this case, a game) using grains
- How to connect an external client to an Orleans cluster (
ClientBuilder
)
The system consists of two parts: a server executable called AdventureServer and a client executable called AdventureClient. The server reads a game data file, AdventureMap.json
by default, and initializes RoomGrain
instances with that game data. The client connects to the server and interacts with the game using the IPlayerGrain
interface. On the server, IPlayerGrain
is implemented by PlayerGrain
, so any calls to IPlayerGrain
are routed to the corresponding PlayerGrain
instance. Clients issue commands to the game by calling IPlayerGrain.Play(command)
, where command
is a string entered by the player at the command prompt. PlayerGrain
interprets each command and executes it, possibly issuing calls to a RoomGrain
to interact with the room.
This is a simple game and there are only a few verbs which the game understands:
look
- to examine the current roomgo <direction>
- to move to a different room.north
,south
,east
,west
- shortcuts forgo north
, etckill <target>
- kill a targetdrop <thing>
- drop something from the player's inventorytake <thing>
- add an item from the current room to the player's inventoryinv
orinventory
- examine the player's inventoryend
- exits the game
Sample prerequisites
This sample is written in C# and targets .NET 7.0. It requires the .NET 7.0 SDK or later.
Building the sample
To download and run the sample, follow these steps:
- Download and unzip the sample.
- In Visual Studio (2022 or later):
- On the menu bar, choose File > Open > Project/Solution.
- Navigate to the folder that holds the unzipped sample code, and open the C# project (.csproj) file.
- Choose the F5 key to run with debugging, or Ctrl+F5 keys to run the project without debugging.
- From the command line:
- Navigate to the folder that holds the unzipped sample code.
- At the command line, type
dotnet run
.
To run the game, run the server by executing the following at the command prompt (opened to the base directory of the sample):
dotnet run --project AdventureServer
You should see the server startup and eventually print the line Press any key to exit
.
In a separate terminal, execute the following to start the client and play the game:
dotnet run --project AdventureClient