Expand description
The game engine: levels, fixtures, answers, requirements and cd policies.
Level authors need one import, prelude:
use shellgame::engine::prelude::*;
// One function per level; the section lists them. Ids are explicit, so reordering
// never renumbers anything.
fn challenge() -> Level {
level(8, "Integrační výzva")
.text("Najděte heslo v sousedním adresáři.")
.start(".")
.hints(["Ze startu přejděte do 'challenge/room1'.", "Přečtěte hint.txt."])
.file("challenge/room1/hint.txt", "Heslo je v sousedním adresáři room2.\n")
.file("challenge/room2/password.txt", "navigator\n")
.answer(
exact("navigator")
.ignore_case()
.error("Heslo není správné. Hledejte password.txt v room2.")
.required("Musíte zadat heslo: shellgame submit <hodnota>"),
)
.require(at("challenge/room2"))
.solution("cd challenge/room2\nshellgame submit \"$(cat password.txt)\"")
.success("Výborně!")
}
let section = Section::new(2, "level-2")
.intro(intro("Práce se soubory", "Úvod."))
.levels([challenge()]);
let catalog = Catalog::new(vec![section]);
assert!(catalog.validate().is_empty());
assert_eq!(catalog.next("2.0".parse().unwrap()), Ok(Some(LevelId::new(2, 8))));The pieces, from the bottom up:
fixture: what a level’s files look like, applied with repair semantics.answerandrequire: how work is judged. Requirements are unconditional and run before the answer; feedback is data (Check), never an error.cd: strictcdpolicies and the anti-soft-lock contract.levelandsection: the builder API and run-time behaviour (Level::prepare,Level::validate).catalog: ordering, navigation andCatalog::validate.
Nothing here reads the process working directory, HOME or the environment: the caller
passes a Ctx explicitly, so every rule is a plain function of its inputs.
Re-exports§
pub use check::Check;pub use ctx::Ctx;pub use fixture::Content;pub use fixture::Fixture;pub use fixture::FixtureError;pub use id::LevelId;pub use section::Section;
Modules§
- answer
- Answer rules: how a submitted answer is judged.
- catalog
- The catalog: every section and level, in course order.
- cd
- Declarative
cdpolicies for strict navigation levels. - check
- The result of checking a player’s work.
- ctx
- Everything a check needs to know about the world, passed explicitly.
- fd
- File-descriptor evidence: where the player’s command sent stdout and stderr.
- fixture
- Declarative workspace fixtures: what a level’s directory must look like.
- id
- Level identifiers.
- level
- The level builder, and what a level does at run time: prepare, validate, start.
- prelude
- Everything a level author needs, in one import: the builder functions and the types they return or take.
- require
- Requirements: conditions on the player’s work that are always checked.
- section
- Sections: a numbered group of levels that share a directory and a base fixture.