diff options
| author | Andreas Grois <andi@grois.info> | 2023-04-02 15:10:52 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2023-04-02 15:10:52 +0200 |
| commit | cc9bbc434d6df6dc6b414547837bb74e2323d262 (patch) | |
| tree | 0bd5021f49b83d9f851f32875bba0597e9da5020 /examples/text-adventure/main.rs | |
| parent | c9880dd12df2c614360cbc85609d859f3652507f (diff) | |
Example project is now runnable.
Diffstat (limited to 'examples/text-adventure/main.rs')
| -rw-r--r-- | examples/text-adventure/main.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/examples/text-adventure/main.rs b/examples/text-adventure/main.rs index 788c3d5..c98441b 100644 --- a/examples/text-adventure/main.rs +++ b/examples/text-adventure/main.rs @@ -1,11 +1,37 @@ //! A small example text adventure, the logic of which is implemented as a Free Monad based eDSL. //! -//! The goal of this game is to buy a sausage roll. +//! The goal of this game is to buy a sausage roll. With pickle. +//! +//! The code of this example contains a few peculiarities, to highlight features of and issues with the current +//! Free Monad code. +//! For instance, it intentionally does not have `Copy` implemented on the player's inventory, to illustrate how +//! one can work around a limitation in the current run!{} macro version. +//! Another thing that is not really that useful in practice is that all strings that are hardcoded are references +//! instead of owned copies. This is just to illustrate that lifetimes are supported too. +//! +//! In a real project, I'd just make all game state (here: inventory) `Copy`, and use owned values wherever possible to make the code +//! more concise. If `Copy` is not an option, I'd probably make a custom version of `run!{}` that allows to clone the +//! game state in a convenient way (see https://github.com/bodil/higher/issues/6). +//! +//! But on to the explanation what is going on: +//! This project has 4 modules: +//! - "data" contains the data. Stuff like item types, item descriptions, rooms, etc. +//! - "dsl" contains the embedded domain specific language. In other words, a Functor and the corresponding Free Monad type (and some helpers) +//! - "logic" describes the game's main logic using the language defined in "dsl" +//! - "side_effects" actually runs the logic. +//! +//! The important part here is that all the stuff that isn't in "side_effects" is independent of the concrete implementation of "side_effects". +//! The current "side_effects" runs a text-adventure, but it could just as well render as a visual-novel, without the need to touch any of the other modules. +mod data; mod dsl; mod logic; mod side_effects; -fn main() { +fn main() -> std::io::Result<()> { + //Let's build the game logic. As a data structure. let game = logic::game(); + + //And now let's do something with it. + side_effects::run(game) }
\ No newline at end of file |
