Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. 'use strict';
  2.  
  3. var Game = require('./ica_mud.js'); //TODO B3
  4. var util = require('util');
  5. var readline = require('readline');
  6. var fs = require('fs');
  7.  
  8.  
  9. //TODO E1
  10. var newMap = [
  11. ["a lake", "a town", "hills"],
  12. ["plains", "a road", "mountains"],
  13. ["a forest", "a forest road", "a cave"]
  14. ];
  15.  
  16. var game = Object.create(Game);
  17. game.init(newMap);
  18.  
  19. //The code concerning the initialization and the usage of the var rl use some Node.js and JavaScript trickery
  20. // that you do not have to understand just yet. Make sure you do understand the switch statement.
  21. var rl = readline.createInterface(process.stdin, process.stdout);
  22.  
  23. rl.setPrompt('action?> ');
  24. rl.prompt();
  25.  
  26. rl.on('line', function (line) {
  27. try {
  28. console.log("You see", look());
  29. } catch (error) {
  30. console.log("Something went wrong: " + error);
  31. }
  32. switch (line.trim()) {
  33. case 'w':
  34. console.log(game.input("NORTH"));
  35. break;
  36. case 'a':
  37. console.log(game.input("WEST"));
  38. break;
  39. case 's':
  40. console.log(game.input("SOUTH"));
  41. break;
  42. case 'd':
  43. console.log(game.input("EAST"));
  44. break;
  45. case 'e':
  46. console.log(game.input("NORTHEAST"));
  47. break;
  48. default:
  49. console.log('The input: ' + line.trim() + ' is not defined');
  50. break;
  51. }
  52.  
  53.  
  54. rl.prompt();
  55.  
  56. }).on('close', function () {
  57. //DEFAULT ^c
  58. console.log('Leaving the game');
  59. process.exit(0);
  60. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement