private VerbResult Main() { // ** THE QUEST ** // ** // ** An adventure game // CLS(); PRINT("Please stand by .... "); PRINT(""); PRINT(""); state = new GameState(); PrintIntro(); CLS(); VerbRoutines verbRoutines = new VerbRoutines(UnknownVerb); InitHandlers(verbRoutines); while (true) { PrintDescription(); PrintDirections(); PrintObjects(); while (true) { string cmd = ""; do { PRINT(""); cmd = (INPUT_s("WHAT NOW")); }while (cmd == ""); Command command = Command.Parse(cmd); VerbResult ret = verbRoutines.Handle(command.Verb, command.Noun); if (ret == VerbResult.Idle) { // NO-OP } else if (ret == VerbResult.Proceed) { break; } else { return(ret); } } } }
private void InitHandlers(VerbRoutines verbRoutines) { Func <string, ObjectRef> byRef = s => state.Objects.Find(s); Func <string, ObjectId> byId = s => state.Objects.IdOf(s); verbRoutines.Add("GO", Go); verbRoutines.Add("GET", byRef, Get); verbRoutines.Add("TAK", byRef, Get); verbRoutines.Add("DRO", byRef, Drop); verbRoutines.Add("THR", byRef, Drop); verbRoutines.Add("INV", Inventory); verbRoutines.Add("I", Inventory); verbRoutines.Add("QUI", Quit); Look look = new Look(state, PRINT); verbRoutines.Add("LOO", byId, Eq(ObjectId.Blank, look.Blank), Else <ObjectId>(look.Any)); verbRoutines.Add("L", byId, Eq(ObjectId.Blank, look.Blank), Else <ObjectId>(look.Any)); verbRoutines.Add("EXA", byId, look.Any); Read read = new Read(state, PRINT); verbRoutines.Add("REA", byId, Eq(ObjectId.Diary, read.Diary), Eq(ObjectId.Dictionary, read.Dictionary), Eq(ObjectId.Bottle, read.Bottle), Else <ObjectId>(read.Unknown)); Open open = new Open(state, PRINT); verbRoutines.Add("OPE", byId, Eq(ObjectId.Box, open.Box), Eq(ObjectId.Cabinet, open.Cabinet), Eq(ObjectId.Case, open.Case), Else <ObjectId>(open.Unknown)); Pour pour = new Pour(state, PRINT); verbRoutines.Add("POU", byId, Eq(ObjectId.Salt, pour.Salt), Eq(ObjectId.Bottle, pour.Formula), Else <ObjectId>(pour.Unknown)); Climb climb = new Climb(state, PRINT); verbRoutines.Add("CLI", byId, Eq(ObjectId.Tree, climb.Tree), Eq(ObjectId.Ladder, climb.Ladder), Else <ObjectId>(climb.Unknown)); Jump jump = new Jump(state, PRINT); verbRoutines.Add("JUM", jump.Any); Dig dig = new Dig(state, PRINT); verbRoutines.Add("DIG", byId, Eq(Any(ObjectId.Blank, ObjectId.Hole, ObjectId.Ground), dig.Hole), Else <ObjectId>(dig.Unknown)); Row row = new Row(state, PRINT); verbRoutines.Add("ROW", byId, Eq(Any(ObjectId.Boat, ObjectId.Blank), row.Boat), Else <ObjectId>(row.Unknown)); Wave wave = new Wave(state, PRINT); verbRoutines.Add("WAV", byId, Eq(ObjectId.Fan, wave.Fan), Else <ObjectId>(wave.Unknown)); Leave leave = new Leave(state, PRINT); verbRoutines.Add("LEA", byId, leave.Any); verbRoutines.Add("EXI", byId, leave.Any); Fight fight = new Fight(state, PRINT); verbRoutines.Add("FIG", byId, Eq(ObjectId.Blank, fight.Blank), Eq(ObjectId.Guard, fight.Guard), Else <ObjectId>(fight.Unknown)); Wear wear = new Wear(state, PRINT); verbRoutines.Add("WEA", byId, Eq(ObjectId.Gloves, wear.Gloves), Else <ObjectId>(wear.Unknown)); }