/// Given a command: process (that is: Execute) the command. /// Return true If the command ends the game, false otherwise. private bool processCommand(Command command) { if(!commandMapper.isCommand(command.CommandWord)) { Console.WriteLine("I don't know what you mean..."); return false; } Response response = commandMapper.getResponse(command.CommandWord); return response.Execute(command); }
/// "Quit" was entered. Check the rest of the command to see /// whether we really quit the game. /// Return true, if this command quits the game, false otherwise. public bool Execute(Command command) { if(command.hasSecondWord()) { Console.WriteLine("Quit what?"); return false; } else { return UI.Agree("Do you really want to quit? "); } }
/// Try to go to one direction. If there is an exit, enter the new /// place, otherwise print an error message. /// Return false(does not end game) public bool Execute(Command command) { if(!command.hasSecondWord()) { // if there is no second word, we don't know where to go... Console.WriteLine("Go where?"); return false; } string direction = command.SecondWord; // Try to leave current place. Place nextPlace = game.CurrentPlace.getExit(direction); if (nextPlace == null) { Console.WriteLine("There is no door!"); } else { game.CurrentPlace = nextPlace; Console.WriteLine(nextPlace.getLongDescription()); } return false; }
/// Print out some Help information. /// Here we print some stupid, cryptic message and a list of the /// command words. public bool Execute(Command cmd) { if (!cmd.hasSecondWord()) { Console.WriteLine( @"You are lost. You are alone. You wander around at the university. Your command words are: {0} {1}", commandMapper.AllCommands, Help()); } else if (responses.ContainsKey(cmd.SecondWord)) { Console.WriteLine(responses[cmd.SecondWord].Help()); } else { Console.WriteLine( @"Unknown command {0}! Command words are {1}", cmd.SecondWord, commandMapper.AllCommands); } return false; }
/// Print out some Help information. /// Here we print some stupid, cryptic message and a list of the /// command words. public bool Execute(Command cmd) { if (!cmd.hasSecondWord()) { Console.WriteLine( @"You are lost. You are alone. You wander around at the university. Your command words are: {0} {1}", CommandMapper.GetAllCommands(), Help()); } else if (details.ContainsKey(cmd.GetSecondWord())) { Console.WriteLine(details[cmd.GetSecondWord()]); } else { Console.WriteLine( @"Unknown command {0}! Command words are {1}", cmd.GetSecondWord(), CommandMapper.GetAllCommands()); } return false; }
/// Given a command: process (that is: Execute) the command. /// Return true If the command ends the game, false otherwise. private bool processCommand(Command command) { string cmd = command.GetCommandWord(); if(!CommandMapper.isCommand(cmd)) { Console.WriteLine("I don't know what you mean..."); return false; } bool toQuit; if (cmd == "help") { toQuit = helper.Execute(command); } else if (cmd == "go") { toQuit = goer.Execute(command); } else { toQuit = quitter.Execute(command); } return toQuit; }