Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var Game = require('./ica_mud.js'); //TODO B3
- var util = require('util');
- var readline = require('readline');
- var fs = require('fs');
- //TODO E1
- var newMap = [
- ["a lake", "a town", "hills"],
- ["plains", "a road", "mountains"],
- ["a forest", "a forest road", "a cave"]
- ];
- var game = Object.create(Game);
- game.init(newMap);
- //The code concerning the initialization and the usage of the var rl use some Node.js and JavaScript trickery
- // that you do not have to understand just yet. Make sure you do understand the switch statement.
- var rl = readline.createInterface(process.stdin, process.stdout);
- rl.setPrompt('action?> ');
- rl.prompt();
- rl.on('line', function (line) {
- try {
- console.log("You see", look());
- } catch (error) {
- console.log("Something went wrong: " + error);
- }
- switch (line.trim()) {
- case 'w':
- console.log(game.input("NORTH"));
- break;
- case 'a':
- console.log(game.input("WEST"));
- break;
- case 's':
- console.log(game.input("SOUTH"));
- break;
- case 'd':
- console.log(game.input("EAST"));
- break;
- case 'e':
- console.log(game.input("NORTHEAST"));
- break;
- default:
- console.log('The input: ' + line.trim() + ' is not defined');
- break;
- }
- rl.prompt();
- }).on('close', function () {
- //DEFAULT ^c
- console.log('Leaving the game');
- process.exit(0);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement