From 42567278d30980b2dfd4ec1c6e5a3577ce386dfc Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 29 Oct 2021 11:32:20 -0500 Subject: [PATCH] add 'cheat' command for quicker testing --- game/src/lib.rs | 12 +++++++++++- src/main.rs | 9 +++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/game/src/lib.rs b/game/src/lib.rs index 55ca729..8d3089b 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -150,6 +150,7 @@ enum RoomName { Room1, /// Duplicate of starting room so I can change things around a little. _Room2, + SortingPuzzle, } impl Default for RoomName { @@ -213,10 +214,16 @@ pub struct State { } impl State { + pub fn cheat (&mut self) { + self.current_room = RoomName::SortingPuzzle; + } + /// Send a line of player input (e.g. "look table") into the game and return /// a Vec of Responses. The runtime should process these responses in order. pub fn step (&mut self, input: &str) -> Vec { + use RoomName::*; + match self.intro_state { IntroState::Stage1 => { self.intro_state = IntroState::Stage2; @@ -259,7 +266,10 @@ impl State { line_response ("`hint` may contain spoilers. `help` will not."), Response::Nonsense, ], - PlayerAction::RoomSpecific (x) => self.room_1 (x), + PlayerAction::RoomSpecific (x) => match self.current_room { + Room1 => self.room_1 (x), + _ => just (line_response ("ERR: Invalid current room")), + } } } diff --git a/src/main.rs b/src/main.rs index c66b039..92b274b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,8 +51,12 @@ fn read_input () -> Result { Ok (buffer) } -fn game () -> Result <()> { +fn game (args: &[String]) -> Result <()> { let mut state = State::default (); + + if args.get (1) == Some (&"cheat".to_string ()) { + state.cheat (); + } let responses = state.step (""); for response in responses.into_iter () { @@ -91,7 +95,8 @@ fn game () -> Result <()> { } fn main () -> Result <()> { - game ()?; + let args: Vec <_> = std::env::args ().collect (); + game (&args [..])?; Ok (()) }