aboutsummaryrefslogtreecommitdiff
path: root/examples/text-adventure/logic.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2023-04-02 15:10:52 +0200
committerAndreas Grois <andi@grois.info>2023-04-02 15:10:52 +0200
commitcc9bbc434d6df6dc6b414547837bb74e2323d262 (patch)
tree0bd5021f49b83d9f851f32875bba0597e9da5020 /examples/text-adventure/logic.rs
parentc9880dd12df2c614360cbc85609d859f3652507f (diff)
Example project is now runnable.
Diffstat (limited to 'examples/text-adventure/logic.rs')
-rw-r--r--examples/text-adventure/logic.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/examples/text-adventure/logic.rs b/examples/text-adventure/logic.rs
index 5df5f6e..dc3ff45 100644
--- a/examples/text-adventure/logic.rs
+++ b/examples/text-adventure/logic.rs
@@ -4,6 +4,7 @@
use std::borrow::Cow;
use higher::{run, Functor, Pure, Bind};
+use super::data::*;
use super::dsl::*;
//Haskell has a when function, and it's nice. Sooo, copy that.
@@ -77,6 +78,7 @@ fn handle_rooms<'a,'s:'a>(room: Location, inventory : Inventory) -> FreeSausageR
run!{
c <= handle_room(room, inventory);
if c.0 != Location::Entrance {
+ //If this were an actual game, we could put a save-point here. At this location the next room to handle is just determined by room and inventory.
handle_rooms(c.0, c.1)
} else {
run!{
@@ -151,7 +153,7 @@ fn handle_shelves<'a, 's: 'a>(inventory : Inventory) -> FreeSausageRoll<'a, 's,
let inventory = inventory.clone();
run!{
check_inventory(inventory.clone());
- handle_refrigerators(inventory.clone())
+ handle_shelves(inventory.clone())
}
}
4 => { run!{
@@ -177,7 +179,7 @@ fn handle_deli<'a,'s:'a>(inventory : Inventory) -> FreeSausageRoll<'a, 's, (Loca
let inventory = inventory.clone();
run!{
check_inventory(inventory.clone());
- handle_refrigerators(inventory.clone())
+ handle_deli(inventory.clone())
}
},
3 => {
@@ -207,7 +209,12 @@ fn handle_checkout<'a,'s:'a>(inventory : Inventory) -> FreeSausageRoll<'a, 's, (
run!{
r <= try_pay(inventory.clone());
match r {
- Ok(inventory) => FreeSausageRoll::pure((Location::Entrance, inventory.clone())),
+ Ok(inventory) => {
+ run!{
+ exposition("You leave the supermarket. Your partner is already waiting outside.");
+ FreeSausageRoll::pure((Location::Entrance, inventory.clone()))
+ }
+ },
Err(inventory) => handle_checkout(inventory.clone()),
}
}