GameDecider.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. if(MIDAS == undefined) {
  2. var MIDAS = {};
  3. }
  4. MIDAS.GameDecider = function(gameConsole, inputParser, gameState) {
  5. var self = this;
  6. this.decide = function(message) {
  7. var gameCommands = gameState.getCommandList();
  8. var gameDescriptions = gameState.getCommandDescriptions();
  9. var commandObject = inputParser.parse(message, gameCommands);
  10. console.log(commandObject);
  11. if(commandObject.error) {
  12. if (commandObject.errorMessage == "help") {
  13. gameConsole.output("The commands available to you are:");
  14. gameConsole.output("----------------------------------");
  15. gameConsole.output("help - Lists all possible commands");
  16. for(var i = 0; i < gameCommands.length; i++) {
  17. gameConsole.output(gameCommands[i] + " - " + gameDescriptions[i]);
  18. }
  19. gameConsole.output("----------------------------------");
  20. } else {
  21. gameConsole.output("I don't understand \"" + commandObject.errorMessage + "\".");
  22. }
  23. } else {
  24. gameState.handleCommandInput(commandObject);
  25. }
  26. };
  27. };