Skip to content

Commit 18725b5

Browse files
committed
add README
1 parent 536e860 commit 18725b5

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

games/humlespring/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Humlespring Text Adventure
2+
3+
A simple text adventure game written in Nushell.
4+
5+
The game utilizes Nushell's functional programming capabilities in managing the game map and player state.
6+
7+
* **Immutable Data Structures**: The game map (`$map`) is defined as a record, which is an immutable data structure. This means the map's contents cannot be changed directly during gameplay, promoting data integrity and predictable game behavior. Locations, exits, items, and NPCs are all defined within this structure.
8+
9+
* **Data Transformation**: The `describe_location` function takes the player state and map as input and transforms this data to produce the location description. It uses the `get` command to access location data and `str join` to format the output, demonstrating functional data manipulation.
10+
11+
* **State Management**: The player state (`$player_state`) is a mutable record, but updates to it are handled in a controlled manner within the main loop. Actions like "go", "take", and "search" update the state by assigning new values to the `$player_state` record.
12+
13+
## How to Play
14+
15+
1. Make sure you have Nushell installed (`https://www.nushell.sh/`).
16+
2. Save the script as `script.nu`.
17+
3. Run the game by executing `nu script.nu` in your terminal.
18+
19+
## Commands
20+
21+
* `look` or `l`: Describe the current location.
22+
* `go` or `move` [direction]: Move in the specified direction (e.g., `go north`).
23+
* `take` or `get` [item]: Pick up an item (e.g., `take leaflet`).
24+
* `inventory` or `i`: View your inventory.
25+
* `talk` [npc]: Talk to a non-player character (e.g., `talk alexander`).
26+
* `search` [object]: Search an object in the current location (e.g., `search tree`).
27+
* `give` [item]: Give an item to an NPC (e.g., `give cat`).
28+
* `quit` or `exit`: Quit the game.
29+
30+
## Goal
31+
32+
Olivia has lost her cat, Mittens. Find Mittens and return her to Olivia in the village square.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ loop {
136136
}
137137
}
138138
"talk" => {
139-
if ($loc_data.npcs | get $noun) == null {
140-
print $"There is no one called '($noun)' here to talk to."
141-
} else {
142-
print ($loc_data.npcs | get $noun)
139+
if ( $noun not-in ( $loc_data.npcs | columns )) {
140+
print $"You cannot talk to ($noun) " } else {
141+
if ($loc_data.npcs | get $noun) == null {
142+
print $"There is no one called '($noun)' here to talk to."
143+
} else {
144+
print ($loc_data.npcs | get $noun)
145+
}
143146
}
144147
}
145148
"search" => {

0 commit comments

Comments
 (0)