1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- if(MIDAS == undefined) {
- var MIDAS = {};
- }
- MIDAS.GameState = function(gameConsole) {
- var self = this;
- var commands = ["say", "look", "exits", "go"];
- var commandsDescription = [
- "Your character speaks whatever you type"
- , "Gathers information about your current surroundings"
- , "Lists all of the ways out of the room"
- , "Moves in the specified direction"
- ];
- var rooms = [ {"id" : 0, "name" : "The Void" , "description" : "Nothing but swirling mist in the blackness.", "exits" : []},
- {"id" : 1, "name" : "Entry Hall", "description" : "The ceiling of the hall is vaulted, with light streaming in through the stained glass windows on either side.", "exits" : [{"command" : "north", "target" : 2, "action" : "You move north."}]}
- ,{"id" : 2, "name" : "Grand Ballroom", "description" : "The cool marble floors glisten with the candlight of the crystal chandeliers above.", "exits" : [{"command" : "south", "target" : 1, "action" : "You waltz south."}]}
- ];
- var playerPosition = 1;
- this.getCommandList = function() {
- return commands;
- };
- this.getCommandDescriptions = function() {
- return commandsDescription;
- };
-
- this.handleCommandInput = function(commandObject) {
- switch(commandObject.command) {
- case commands[0]:
- gameConsole.output("You said \"" + commandObject.data.join(" ") + "\"");
- break;
- case commands[1]:
- gameConsole.output(rooms[playerPosition].name);
- gameConsole.output(rooms[playerPosition].description);
- break;
- case commands[2]:
- var exitsList = [];
- if(rooms[playerPosition].exits.length == 0) {
- gameConsole.output("There are no obvious exits.");
- } else {
- for(var i = 0; i < rooms[playerPosition].exits.length; i++) {
- exitsList.push(rooms[playerPosition].exits[i].command);
- }
- gameConsole.output("There are exits to the " + exitsList.join(", "));
- }
- break;
- case commands[3]:
- var exit = {};
- for(var i = 0; i < rooms[playerPosition].exits.length; i++) {
- if(commandObject.data[0] == rooms[playerPosition].exits[i].command){
- exit = rooms[playerPosition].exits[i];
- }
- }
- console.log(exit);
- if (exit.target) {
- gameConsole.output(exit.action);
- playerPosition = exit.target;
- gameConsole.output(rooms[playerPosition].name);
- gameConsole.output(rooms[playerPosition].description);
- } else {
- gameConsole.output("I don't see that exit.");
- }
- break;
- }
- };
- };
|