public string Input(string userCommand) { if (userCommand == "exit") {_inPlay = false; return null;} if (state == null) { //it must be the first go! state = factory.Create(); commandParser = new CommandParser(new VerbRepository(), state); return state.Location.Description; } try { var meaningfulCommand = commandParser.Parse(userCommand); meaningfulCommand.Execute(state); return state.Location.Description + state.Location.NearObjects.Description; } catch (NoVerbException) { return "I couldn't find a verb in that sentence, perhaps you are using a verb outside my limited vocabulary"; } catch (NoWayThereException) { return "That way is blocked"; } }
public CommandParser(IVerbRepository verbRepository, GameState gameState) { _verbRepository = verbRepository; this.gameState = gameState; }
public void Execute(GameState state) { Verb.Do(VerbTool, VerbObject, state); }