Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>
	<head>
	</head>
	<body>
		
		<div class="view"> 
			<h1 style="color:white;margin: 0px 20%;">U are playing: Space Troubles!</h1>
			<div class="hud">
				<div class="wrapper">
					<div id="currentlocation" class="col-5"></div>
					<div id="lastcommand" class="col-5"></div>
				</div>
				<div id="roomdescription"></div>
			</div>
			<div id="output" class="console">
				<div id="userfeedback"></div>
			</div>
			<div class="input">
				<input type="text" id="input" class="inputfield"/>
			</div>
		</div>
	</body>
</html>
            
          
!
            
              body{
				background-color:rgba(0,0,0,0.6);
			}
			.console{
				
				background-color: black;
				color:white;
				margin-left:20%;
				margin-right:20%;
				padding:5px 15px;
				height:450px;
				overflow-y: scroll;
			}
			.input{
				margin-left:20%;
				margin-right:20%;
			}
			.inputfield{
				background-color:black;
				color:white;
				width:100%;
				margin-top: 2px;
			}
			#currentlocation{
				margin-top: 5px;
			}
			#roomdescription{
				margin-top: 10px;
			}
			#lastcommand{
				margin-top: 5px;
			}
			#userfeedback{
			}
			.hud{
				background-color: black;
				color:white;
				margin-left:20%;
				margin-right:20%;
				padding:5px 15px;
				height: 60px;
				border-bottom: 1px dashed white;
			}
			
			.col-5{
				width:50%;
			}
			.wrapper{
			  display: flex;
			  flex-direction: row;
			  border: 1px solid black;
			}
            
          
!
            
              
class Command{	
	constructor(id, command, description){
		this.id = id;						// identifier
		this.command = command;				// the first part of command if there is a second. Reqognized by space
		this.description = description; 	// hold a description of a command.
	}
	run(){
		return [this.command+" does not have yet any functionality."];
	}
}

class Player{
	constructor(){
	}
	move(direction){
		if(this.isValidDirection(direction)){
			this.currentRoom = this.currentRoom.getNeighbour(direction);
			return true;
		}
		return false;
	}
	isValidDirection(direction){
		// check if direction is valid.
		let validDirections = Object.keys(this.currentRoom.neighbours);
		for (let i = 0; i < validDirections.length; i++)
			if(direction == validDirections[i])
				return true;
		return false;
	}
}
class Door{
	constructor(isOpen, key){
		this.isOpen = isOpen;
		this.lock; // contains the code of the key that is needed.
	}
	OpenDoor(key){
		if(key === lock)
			this.isOpen = true;
	}
	closeDoor(){
		this.isOpen = false;
	}
	lockDoor(key){
		this.lock = key;
	}
}

class Room{
	constructor(id, name, description, longDesc){
		this.id = id;
		this.name = name;								// contains the name of the room.
		this.description = description;					// contains a short description of the room.
		this.longDesc = longDesc;						// contains a longer explenation of the room.
		this.neighbours = {}; 							// {"direction": Room}
		this.doors = {};								// {"direction": Door}
		this.objects = [];
		this.items = [];
		
		this.defaultDescription = longDesc;			// contains the default description. Purpose is read only.
	}
	getNeighbour(direction){
		try{
			return this.neighbours[direction];
		}catch(exception){
			console.warn(exception);
			return 0;
		}
	}
	setNeighbours(neighbours){
		let validDirections = VALID_DIRECTIONS;

		
		// check for doors.
		for (let i = 0; i < validDirections.length; i++){
			if (validDirections[i] in this.doors && validDirections[i] in neighbours){
				// set the neighbour
				this.neighbours[validDirections[i]] = neighbours[validDirections[i]];
			}
		}
	}
	getCopy(){
		return new Room(this.id, this.name, this.description, this.longDesc);
	}
}

class Furniture{
	constructor(id, name, description, longDesc){
		this.id = id;
		this.name = name;					// contains the name of the room.
		this.description = description;		// contains a short description of the room.
		this.longDesc = longDesc;			// contains a longer explenation of the room.
	}
}

class Quest{
	constructor(id, objective, keyCommand, objectiveRoom){
		this.id = id;
		this.objective = objective; 			// short description of quest.
		this.completed = false;
		this.keyCommand = keyCommand;			// holds the command needed for the quest
		this.objectiveRoom = objectiveRoom;		// holds the room the quest can be completed in.
		this.questdescriptions = {};			// { 'room id': description }
		this.questObjects = {};					// { 'room id': Furniture }
	}
	load(){
		let allQuestdescriptions = Object.keys(this.questdescriptions);
		for (let i = 0; i < allQuestdescriptions.length; i++){
			this.replaceDescription(allQuestdescriptions[i], this.questdescriptions[allQuestdescriptions[i]]);
		}
		
	}
	replaceDescription(roomid, description){
		// make sure roomid = int
		var parsedRoomID = parseInt(roomid);
		for(let x = 0; x < MAP.length; x++)
			for(let y = 0; y < MAP[x].length; y++)
				if (MAP[x][y].id === parsedRoomID)
					MAP[x][y].longDesc = description;
	}
	unload(){
		for(let x = 0; x < MAP.length; x++)
			for (let y = 0; y < MAP[x].length; y++)
				MAP[x][y].longDesc = MAP[x][y].defaultDescription;
	}
}

class Game{	
	constructor(spawnRoom){
		this.world = MAP;
		this.player = new Player();
		this.player.currentRoom = spawnRoom;
		this.started = false;
		this.hasended = false;
	}
	load(){
		// set replacement rooms.
		for (let x = 0; x < this.world.length; x++){
			for (let y = 0; y < this.world[x].length; y++){
				let currentfloor = this.world[x][y];
				// Spacefillers
				if(currentfloor.id === 0)					
					this.world[x][y] = ROOM_00.getCopy();
			}
		}
		
		// genrate the neighbours for each room
		for (let x = 0; x < this.world.length; x++){
			for (let y = 0; y < this.world[x].length; y++){
				let currentfloor = this.world[x][y];
				let allNeighbours = this.getNeighbours(this.world, x, y);
				currentfloor.setNeighbours(allNeighbours); 
			}
		}
	}
	getNeighbours(world, x, y){
        let posX = x;
        let posY = y;
		
		// define min/max array out of bounce protection.
		let minY  = posY - 1 >= 0 ? posY - 1 : 0;
		let maxY  = posY + 1 <= world[x].length-1 ? posY + 1 : world[x].length-1;
		
		let minX = posX - 1 >= 0 ? posX - 1 : 0;
		let maxX = posX + 1 <= world.length-1 ? posX + 1 : world.length-1;
		
		let result = {};
		
		// set neighbor if there is one;
		if(posY != minY ) 
			result["west"] = world[posX][minY];
		
		if(posY != maxY )
			result["east"] = world[posX][maxY];
		
		if(posX != maxX )
			result["south"] = world[maxX][posY];
		
		if(posX != minX )
			result["north"] = world[minX][posY];
		
        return result;
    }
	getCurrentState(input, userfeedback){
		let resultsToPrint = {	// contains all the results the system has to print. (e.i. names, descriptions.)
			"currentroom"		: 	this.player.currentRoom.name,
			"roomdescription"	:	this.player.currentRoom.description,
			"userfeedback"		:	[],
			"lastcommand"		: 	input
		};			
		
		
		for(let i = 0; i < userfeedback.length; i++){
			if(userfeedback[i] !== "")
				resultsToPrint["userfeedback"].push(userfeedback[i]);	
		}
		return resultsToPrint;
	}
}
	

class CommandController{		// decides what to do when a command is called.	
	constructor( game){
		this.game = game;
	}
	runCommand(input){
		
		
		// prepare the input so it can be used.
		let inputBrokenDown = this.prepareCommand(input);	// works
		
		// if there is no command do nothing
		if (inputBrokenDown.length === 0)	// works as expected.
			return [];
			
		// check if command is valid.
		if(!this.isValidCommand(inputBrokenDown[0]))
			return [ERROR_COMMAND_NOT_FOUND];
		
		let results = [];
		//decide what function to call on given command.
		switch (inputBrokenDown[0]){
			case "help":	// Display all the command information
				if(inputBrokenDown[1]!==undefined)
					results = this.commandHelp(inputBrokenDown[1]);
				else
					results = this.help();
				break;
			case "go":
				if(inputBrokenDown[1]!==undefined)
					results = this.go(inputBrokenDown[1]);
				else
					results = [MSG_PICK_A_DIRECTION];
				break;
			case "inspect":
				if(inputBrokenDown[1]!==undefined)
					results = this.inspect(inputBrokenDown[1]);
				else
					results = [MSG_INSPECT_WHAT];
				break;
			case "direction":
					results = this.direction();
				break;
			case "repair":
					results = this.repair(inputBrokenDown[1]);
				break;
			default:
				results = [ERROR_COMMAND_NOT_CREATED];
				
		}
		return results;// 	results = array of strings
	}
	repair(input){// dirty hack so quest commands are seen as valid. TODO: do it the proper way
		let result = [];
		if(input === "generator")
			result.push();
		else
			result.push(`cannot find object.`)
		return result;
	}
	direction(){
		return this.commandHelp("go");
	}
	go(input){
		// check if valid direction
		if(!this.isValidDirection(input))
			return [ERROR_INVALID_DIRECTION];
		
		let player = this.game.player;
		// move player to direction
		let playerHasMoved = player.move(input);
		if(playerHasMoved){
			let result = [];
			result.push(`${TXT_MOVE} ${input}. ${TXT_TOWARDS} ${player.currentRoom.name}</br> *>`);
			result.push(player.currentRoom.longDesc);
			return result;
		}else
			return [MSG_PATH_BLOCKED];
	}
	inspect(input){
		let results = [];
		let currentRoom = this.game.player.currentRoom;
		
		if(input === "room"){
			results.push(currentRoom.longDesc);
		}
		
		let objInCurrentRoom = currentRoom.objects;
		for(let i = 0; i < objInCurrentRoom.length; i++)
			if(objInCurrentRoom[i].name === input)
				results.push(objInCurrentRoom[i].longDesc);
			
		let itemsInCurrentRoom = this.game.player.currentRoom.items;
		for(let i = 0; i < itemsInCurrentRoom.length; i++)
			if(itemsInCurrentRoom[i].name === input)
				results.push(itemsInCurrentRoom[i]);
		
		return results;
	}
	isValidDirection(dir){
		let validDirections = VALID_DIRECTIONS;
		for(let i = 0; i < validDirections.length; i++)
			if(dir === validDirections[i])
				return true;
		return false;
	}
	isValidCommand(cmd){
		let validCommands = VALID_COMMANDS;
		for(let i = 0; i < validCommands.length; i++)
			if (cmd == validCommands[i].command)
				return true;
		return false;
	}
	help(){
		let validCommands = VALID_COMMANDS;
		let results = [];
		results.push(MSG_GET_HELP);
		for (let i = 0; i < validCommands.length; i++)
			results.push("<b>- "+validCommands[i].command +": </b>" + validCommands[i].description);
		return results;
	}
	commandHelp(cmd){
		let results = [];
		switch (cmd){
			case "go":
				let roomneighbours = this.game.player.currentRoom.neighbours;
				let validDirections = Object.keys(roomneighbours);
				results.push(MSG_VALID_DIRECTIONS);
				for(let i = 0; i < validDirections.length; i++)
					results.push("<b>- "+validDirections[i]+": </b>"+roomneighbours[validDirections[i]].name);
				break;
			case "inspect":
					results.push(COMMAND_INSPECT.description);
				break;
			default:
				results.push(ERROR_INCORRECT_VALUE);
		}
		return results;
	}
	prepareCommand(input){
		let result =  "";
		if (input)
			result = input.split(" ");
		return result;
	}
}

class OutputController{
	constructor(){
	}
	load(){
		this.outputCurrentLocation = document.getElementById("currentlocation");
		this.outputUserFeedback = document.getElementById("userfeedback");
		this.outputRoomdescription = document.getElementById("roomdescription");
		this.outputArea = document.getElementById('output');
		this.outputLastCommand = document.getElementById('lastcommand');
	}
	drawStep(data, input){
		this.updateCurrentLocation(data);
		this.updateRoomdescription(data);
		this.updateUserFeedback(data);
		this.updateLastCommand(input);
	}
	updateCurrentLocation(data){
		this.outputCurrentLocation.innerHTML = "";
		let line = document.createElement('span');
		line.innerHTML = "<b>"+TXT_CURRENT_ROOM+"</b>" + data["currentroom"];
		this.outputCurrentLocation.appendChild(line); 
	}
	updateRoomdescription(data){
		this.outputRoomdescription.innerHTML = "";
		let line = document.createElement('span');
		line.innerHTML = "<b>"+TXT_ROOM_DESCRIPTION+"</b>" + data["roomdescription"];
		this.outputRoomdescription.appendChild(line);
	}
	updateLastCommand(input){
		// display command back to user
		if(input !== undefined){
			this.outputLastCommand.innerHTML = "";
			let userCommand = document.createElement('span');
			userCommand.innerHTML = `<b>${TXT_LAST_COMMAND}</b> ${input}`;			
			this.outputLastCommand.appendChild(userCommand);
			this.outputLastCommand.appendChild(document.createElement('br'));
		}
	}
	updateUserFeedback(data){
		// display feedback from given command
		for(let i = 0; i < data["userfeedback"].length; i++){
			let newLine = document.createElement('br');
			let line = document.createElement('span');
			line.innerHTML = data["userfeedback"][i];
			this.outputUserFeedback.appendChild(line);
			this.outputUserFeedback.appendChild(newLine);
		}
		let devider = document.createElement('span');
		devider.innerHTML = TXT_DEVIDER;
		this.outputUserFeedback.appendChild(devider);
		this.updateScroll(this.outputArea, false);
	}
	clearUserFeedback(){
		this.outputUserFeedback.innerHTML = "";
	}
	updateScroll(el, scrolled){
		if(!scrolled){
			el.scrollTop = el.scrollHeight;
		}
	}
	insertLine(msg){
		
		let message = document.createElement('span');
		message.innerHTML = msg;
		this.outputUserFeedback.appendChild(message);
		
		let devider = document.createElement('span');
		devider.innerHTML = TXT_DEVIDER;
		this.outputUserFeedback.appendChild(devider);
		
		this.updateScroll(this.outputArea, false);
	}
}


//--------------------
// Data
//--------------------

//--------------------
// Commands
//--------------------
let COMMAND_HELP 				= new Command( 0, 	`help`, 		`Display all the available commands.`);
let COMMAND_GO 					= new Command( 1, 	`go`, 			`Go to a direction. Type "go [direcrion]" to move to a diffrent room.`);
let VALID_DIRECTIONS			= ["north", "south", "east", "west"];	// all valid directions for the COMMAND_GO
let COMMAND_VALID_DIRECTIONS	= new Command( 2, 	`direction`, 	`Gives information of all valid directions for the current room.`);
let COMMAND_INSPECT				= new Command( 3, 	`inspect`, 		`Inspect something better. Type "Inspect [room|object]" to get more information.`)
let COMMAND_REPAIR				= new Command( 4, 	`repair`, 		`Used to repair objects that are broken.`) // TODO: how to implement quest specific commands ?

let VALID_COMMANDS 				= [COMMAND_HELP, COMMAND_GO, COMMAND_VALID_DIRECTIONS, COMMAND_INSPECT, COMMAND_REPAIR];

let PLAYER_NAME					= `Ricardo`;
let NPC_1						= `Miria`;		// Very creative. Has paintings and artwork all over the ship. 
let NPC_2						= `Scott`;		// Is not very interesting. Does not own alot of stuff and always keeps his stuff clean.
let NPC_3						= `Lodash`;		// Came originally from mars. Always tells the funniest jokes.
let NPC_4						= `Phillip`;	// Is a workoholic. He often spends his time on phisics and math. U once had to wake up the whole crew to get philip back into hypersleep.
let NPC_5						= `Clara`;		// Alwasy talks about she used to travel in time.


//--------------------
// Default furniture
//--------------------

let DISPLAY_PLAYER_POD		= new Furniture(0, `display`,	`This is a display hanging on the wall.`, `	*> Status ${NPC_3}: Hyper sleep.<br/>
																										*> Status ${PLAYER_NAME}: Woken up.<br/>
																										*> Status Peter: Hyper sleep.<br/>
																										*> <br/>
																										*> *WARNING* Generator has been damaged. Manual repair is needed.<br/>
																										`);
																										
let INSTRUCTIONS_R3				= new Furniture(2, `instructions`, `The instructions read:</br>
																	This escape pod is one use only. Only use in case of emergency.</br>
																	- Open door</br>
																	- Sit in chair and fasten seatbelts.</br>
																	- 
																	-
																	-`);

//--------------------
// Rooms
//--------------------

// space filler. since map is expected to be x*x
let ROOM_00						= new Room(0, 	`Room not found!`, 				`Your standing in a room that does not excist. Weird...`, `.......`);

// Rooms on ship
let ROOM_01						= new Room(1, 	`Engine room A`, 				`Room 01: Engine A`,		`This room is very big. The whole west wall is covered with engine. Despite the space of the room there is not much room to walk around in. Besides a lot of cable's there is a small desk with a display in the north-east corner.`);
ROOM_01.doors["east"] 			= new Door(true);


let ROOM_02						= new Room(2, 	`Engine room B`, 				`Room 02: Engine B`,		`This room is very big. The whole west wall is covered with engine. Despite the space of the room there is not much room to walk around in. The room smells lightly of chemicals. There is a giant wall painting of a dog meeting his hero for the first time on the east wall, </br> ${NPC_1} probably did that.` );
ROOM_02.doors["east"] 			= new Door(true);

let ROOM_03						= new Room(3,	`Escape pod A`,					`Room 03: Escape pod A`,	`On the north side there are three doors with instructions. They doors are numbered 1, 2, 3. The door with the number 3 has flowers </br>painted around them. Every door has a instructions on them.`);
ROOM_03.doors["south"] 			= new Door(true);
ROOM_03.objects.push(INSTRUCTIONS_R3);

let ROOM_04						= new Room(4,	`Escape pod B`,					`Room 04: Escape pod B`,	`On the north side there are three doors with instructions. They doors are numbered 4, 5, 6. Every door has a instructions on them. </br>`);
ROOM_04.doors["north"] 			= new Door(true);
ROOM_04.objects.push(INSTRUCTIONS_R3);

let ROOM_05						= new Room(5,	`Hyper sleep bedroom A`,		`Room 05: H.S. Bedroom A`,	`There are three sleeping pods in the room. All three sleepingpods are already in use.`);
ROOM_05.doors["south"] 			= new Door(true);

let ROOM_06						= new Room(6,	`Hyper sleep bedroom B`,		`Room 06: H.S. Bedroom B`,	`There are three sleeping pods in the room. One of them is your's. The other two sleepingpods are already in use.`);
ROOM_06.doors["north"] 			= new Door(true);
ROOM_06.objects.push(DISPLAY_PLAYER_POD);

let ROOM_07						= new Room(7,	`Energy generator`,				`Room 07: Energy generator`, `There is a big glass structure in the middle of the room. The structure has a green glowing and pulsing sphere inside. The sphere looks to be stable.`);
ROOM_07.doors["north"] 			= new Door(true);

let ROOM_08						= new Room(8,	`Energy condenser`,				`Room 08: Energy condenser`,`There is a very big machine filling the room that is responsible for condensing the energy that is created by the ship's energy generator. This room is condensing energy right now. This is normal behavior after the ship had to repair itself.`);
ROOM_08.doors["south"] 			= new Door(true);

let ROOM_09						= new Room(9,	`Main computer`,				`Room 09: Ship's main computer`,`A big computer fills up the room. The walls are filled with display's that show the current status of the ship. The main display say's "Auto pilot: Active."`);
ROOM_09.doors["north"] 			= new Door(true);

let ROOM_10						= new Room(10,	`Anti gravity room`,			`Room 10: Anti gravity room`,`The room is completely empty. By activating the anti-gravity, It currently does not work because the ship has low power.`);

ROOM_10.doors["south"] 			= new Door(true);

let ROOM_11						= new Room(11,	`Medical bay`,					`Room 11: Medical bay`,`The room smells sterile. There are alot of cabinets that contain medicine and other items that help a person get healthy. The cabinets are locked for unauthorized personal.`);
ROOM_11.doors["north"] 			= new Door(true);

let ROOM_12						= new Room(12,	`Gym`,							`Room 12: Gym`,`A spacious room with all kind of fitniss equipment. The best place to stay fit and healthy.`);
ROOM_12.doors["south"] 			= new Door(true);

let ROOM_13						= new Room(13,	`Laboratory`,					`Room 13: Laboratory`,`This laboratory seems to be in use by one of youre crew mates. Biology experiments are going on in this room. Warning holograms are flying around saying "Don't touch anything".`);
ROOM_13.doors["north"] 			= new Door(true);

let ROOM_14						= new Room(14,	`Bedroom A`,					`Room 14: Bedroom "${NPC_1}" and "${NPC_2}"`,`On the east side is obviously ${NPC_1}'s side. Above her bed hangs a painting of a kitten hanging from a branch. The west side is reserved for ${NPC_2}. ${NPC_2}'s side looks very clean and he does not seem to have that much stuff.`);
ROOM_14.doors["south"] 			= new Door(true);

let ROOM_15						= new Room(15,	`Holo deck`,					`Room 15: Holo deck`,`Everything is possible in this room. By pressing the button next to the door you get a random scenario you can live trough. This is a whole new way of experiencing a good story.`);
ROOM_15.doors["north"] 			= new Door(true);

let ROOM_16						= new Room(16,	`Bedroom B`,					`Room 16: Bedroom "${NPC_3}" and "${PLAYER_NAME}"`,`${NPC_3}'s side has some pretty weird artwork on the wall. He's from mars and their culture is very diffrent. You'r side looks very nice. Well done.`);
ROOM_16.doors["south"] 			= new Door(true);

let ROOM_17						= new Room(17,	`Lounge`,						`Room 17: Lounge`,`There is a display on the east wall that can be used for entertainment. On the west side of the room there are some comfy chairs around a coffee table. `);
ROOM_17.doors["north"] 			= new Door(true);

let ROOM_18						= new Room(18,	`Bedroom C`,					`Room 18: Bedroom "${NPC_4}" and "${NPC_5}"`,`${NPC_4}'s side has a picture on the wall of a time we all needed to wake up to put him back into hyper sleep. Those where times. ${NPC_5} has a small blue police box on her bedstand.`);
ROOM_18.doors["south"] 			= new Door(true);

let ROOM_19						= new Room(19,	`Mess hall`,					`Room 19: Kitchen/Kantine`,`Food can be chosen on the north wall. Drinks can be chosen on the west wall. A food dispencer in the north west corner will create your choise out of energy. Cause its the future.`);
ROOM_19.doors["north"] 			= new Door(true);
ROOM_19.doors["east"] 			= new Door(true);

let ROOM_20						= new Room(20,	`Converence room`,				`Room 20: Converence room`,`There is a round table with 6 chairs in the middle of the room. This room is used to hold a converence when needed. Its a little dusty. This room hasn't been used in years.`);
ROOM_20.doors["south"] 			= new Door(true);

let ROOM_21						= new Room(21,	`Oxygen factory N`,				`Room 21: Oxygen factory North`,`There is a giant forest in this room that produces oxygen. The tree's have been specially wired to make sure they get the correct nourishment. On the walls there is a big N indicating this is the nort side of the forest.`);
ROOM_21.doors["north"] 			= new Door(true);
ROOM_21.doors["south"] 			= new Door(true);
ROOM_21.doors["west"] 			= new Door(true);

let ROOM_22						= new Room(22,	`Oxygen factory S`,				`Room 21: Oxygen factory South`,`There is a giant forest in this room that produces oxygen. The tree's have been specially wired to make sure they get the correct nourishment. On the walls there is a big S indicating this is the south side of the forest.`);
ROOM_22.doors["north"] 			= new Door(true);
ROOM_22.doors["south"] 			= new Door(true);
ROOM_22.doors["west"] 			= new Door(true);

let ROOM_23						= new Room(23,	`Navigation room`,				`Room 22: Navigation room/Bridge`,`In the middle of the room there is a round wheel that is used for steering the ship. The wheel is currently locked in position. The walls are covered with display's displaying information as to where the ship currently. The main display read's "Auto pilot: Active"`); 
ROOM_23.doors["north"] 			= new Door(true);
ROOM_23.doors["east"] 			= new Door(true);

let ROOM_24						= new Room(24,	`Communication room`,			`Room 23: Communication room`,`This room controlles all the communication. The monthly log would be send from here if it where the time.`); 
ROOM_24.doors["east"] 			= new Door(true);
ROOM_24.doors["south"] 			= new Door(true);

let ROOM_25						= new Room(25,	`Ship's defence system`,		`Room 25: Armory/Defencesystem`,`This room is only activated in case of thread. Currently it is very dark because the lights are out. All you can make out is a big black box in the north east corner and a big display on the south wall. The display can't be turned on.`);
ROOM_25.doors["west"] 			= new Door(true);

let ROOM_26						= new Room(26,	`Shield generator`,				`Room 26: Shield generator`,`In the middle of the room there is a hologram of the ship. Around the ship there is a sphere that indicates the shield. The shield looks to be in good condition.`);
ROOM_26.doors["west"] 			= new Door(true);

// Hallway's
// North Hallway
let ROOM_N01 					= new Room(27, `Hallway N01`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N01.doors["north"] 		= new Door(true);
ROOM_N01.doors["east"] 			= new Door(true);
ROOM_N01.doors["south"] 		= new Door(true);
ROOM_N01.doors["west"] 			= new Door(true);

let ROOM_N02					= new Room(28, `Hallway N02`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N02.doors["north"] 		= new Door(true);
ROOM_N02.doors["east"] 			= new Door(true);
ROOM_N02.doors["south"] 		= new Door(true);
ROOM_N02.doors["west"] 			= new Door(true);

let ROOM_N03 					= new Room(29, `Hallway N03`,`Hallway North side`,`There are three hallways connecting. These hallways lead east, south and west. On the north wall there is a emergency sign.`);
ROOM_N03.doors["east"] 			= new Door(true);
ROOM_N03.doors["south"] 		= new Door(true);
ROOM_N03.doors["west"] 			= new Door(true);

let ROOM_N04 					= new Room(30, `Hallway N04`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N04.doors["east"] 			= new Door(true);
ROOM_N04.doors["south"] 		= new Door(true);
ROOM_N04.doors["west"] 			= new Door(true);

let ROOM_N05 					= new Room(31, `Hallway N05`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N05.doors["east"] 			= new Door(true);
ROOM_N05.doors["south"] 		= new Door(true);
ROOM_N05.doors["west"] 			= new Door(true);

let ROOM_N06 					= new Room(32, `Hallway N06`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N06.doors["east"] 			= new Door(true);
ROOM_N06.doors["south"] 		= new Door(true);
ROOM_N06.doors["west"] 			= new Door(true);;

let ROOM_N07 					= new Room(33, `Hallway N07`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N07.doors["east"] 			= new Door(true);
ROOM_N07.doors["south"] 		= new Door(true);
ROOM_N07.doors["west"] 			= new Door(true);

let ROOM_N08 					= new Room(34, `Hallway N08`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N08.doors["east"] 			= new Door(true);
ROOM_N08.doors["south"] 		= new Door(true);
ROOM_N08.doors["west"] 			= new Door(true);

let ROOM_N09 					= new Room(35, `Hallway N09`,`Hallway North side`,`There are three hallways connecting. These hallways lead east, south and west. On the north wall there is a emergency sign.`);
ROOM_N09.doors["east"] 			= new Door(true);
ROOM_N09.doors["south"] 		= new Door(true);
ROOM_N09.doors["west"] 			= new Door(true);

let ROOM_N10 					= new Room(36, `Hallway N10`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N10.doors["east"] 			= new Door(true);
ROOM_N10.doors["south"] 		= new Door(true);
ROOM_N10.doors["west"] 			= new Door(true);

let ROOM_N11					= new Room(37, `Hallway N11`,`Hallway North side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_N11.doors["east"] 			= new Door(true);
ROOM_N11.doors["south"] 		= new Door(true);
ROOM_N11.doors["west"] 			= new Door(true);

// Connector Hallways
let ROOM_C01 					= new Room(38, `Hallway C01`,`Hallway Connector`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_C01.doors["north"] 		= new Door(true);
ROOM_C01.doors["south"] 		= new Door(true);

let ROOM_C02 					= new Room(39, `Hallway C02`,`Hallway Connector`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_C02.doors["north"] 		= new Door(true);
ROOM_C02.doors["south"] 		= new Door(true);

let ROOM_C03 					= new Room(40, `Hallway C03`,`Hallway Connector`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_C03.doors["north"] 		= new Door(true);
ROOM_C03.doors["east"] 			= new Door(true);
ROOM_C03.doors["south"] 		= new Door(true);
ROOM_C03.doors["west"] 			= new Door(true);

let ROOM_C04 					= new Room(41, `Hallway C04`,`Hallway Connector`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_C04.doors["north"] 		= new Door(true);
ROOM_C04.doors["south"] 		= new Door(true);


// South Hallways
let ROOM_S01 					= new Room(42, `Hallway S01`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S01.doors["north"] 		= new Door(true);
ROOM_S01.doors["east"] 			= new Door(true);
ROOM_S01.doors["south"] 		= new Door(true);
ROOM_S01.doors["west"] 			= new Door(true);

let ROOM_S02 					= new Room(43, `Hallway S02`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S02.doors["north"] 		= new Door(true);
ROOM_S02.doors["east"] 			= new Door(true);
ROOM_S02.doors["south"] 		= new Door(true);
ROOM_S02.doors["west"] 			= new Door(true);

let ROOM_S03 					= new Room(44, `Hallway S03`,`Hallway South side`,`There are three hallways connecting. These hallways lead north, east and west. On the south wall there is a emergency sign.`);
ROOM_S03.doors["north"] 		= new Door(true);
ROOM_S03.doors["east"] 			= new Door(true);
ROOM_S03.doors["west"] 			= new Door(true);

let ROOM_S04 					= new Room(45, `Hallway S04`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S04.doors["north"] 		= new Door(true);
ROOM_S04.doors["east"] 			= new Door(true);
ROOM_S04.doors["west"] 			= new Door(true);

let ROOM_S05 					= new Room(46, `Hallway S05`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S05.doors["north"] 		= new Door(true);
ROOM_S05.doors["east"] 			= new Door(true);
ROOM_S05.doors["west"] 			= new Door(true);

let ROOM_S06 					= new Room(47, `Hallway S06`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S06.doors["north"] 		= new Door(true);
ROOM_S06.doors["east"] 			= new Door(true);
ROOM_S06.doors["west"] 			= new Door(true);

let ROOM_S07 					= new Room(48, `Hallway S07`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S07.doors["north"] 		= new Door(true);
ROOM_S07.doors["east"] 			= new Door(true);
ROOM_S07.doors["west"] 			= new Door(true);

let ROOM_S08 					= new Room(49, `Hallway S08`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S08.doors["north"] 		= new Door(true);
ROOM_S08.doors["east"] 			= new Door(true);
ROOM_S08.doors["west"] 			= new Door(true);

let ROOM_S09 					= new Room(50, `Hallway S09`,`Hallway South side`,`There are three hallways connecting. These hallways lead north, east and west. On the south wall there is a emergency sign.`);
ROOM_S09.doors["north"] 		= new Door(true);
ROOM_S09.doors["east"] 			= new Door(true);
ROOM_S09.doors["west"] 			= new Door(true);

let ROOM_S10 					= new Room(51, `Hallway S10`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S10.doors["north"] 		= new Door(true);
ROOM_S10.doors["east"] 			= new Door(true);
ROOM_S10.doors["west"] 			= new Door(true);

let ROOM_S11 					= new Room(52, `Hallway S11`,`Hallway South side`,`You are inside a hallway. Its well kept en spacey.`);
ROOM_S11.doors["north"] 		= new Door(true);
ROOM_S11.doors["east"] 			= new Door(true);
ROOM_S11.doors["west"] 			= new Door(true);

// spawn room for player. Since player needs to accept to go on spaceship
let ROOM_100					= new Room(100, `${PLAYER_NAME}'s bedroom`, 		`This is the bedroom of ${PLAYER_NAME}. It's where it all starts.`);

let MAP = [ 
	[ROOM_00, ROOM_03 , ROOM_05 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00],
	[ROOM_01, ROOM_N01, ROOM_N02, ROOM_N03, ROOM_N04, ROOM_N05, ROOM_N06, ROOM_N07, ROOM_N08, ROOM_N09, ROOM_N10, ROOM_N11, ROOM_00],
	[ROOM_00, ROOM_07 , ROOM_09 , ROOM_C01, ROOM_11 , ROOM_13 , ROOM_15 , ROOM_17 , ROOM_19 , ROOM_C03, ROOM_21 , ROOM_23 , ROOM_25],
	[ROOM_00, ROOM_08 , ROOM_10 , ROOM_C02, ROOM_12 , ROOM_14 , ROOM_16 , ROOM_18 , ROOM_20 , ROOM_C04, ROOM_22 , ROOM_24 , ROOM_26],
	[ROOM_02, ROOM_S01, ROOM_S02, ROOM_S03, ROOM_S04, ROOM_S05, ROOM_S06, ROOM_S07, ROOM_S08, ROOM_S09, ROOM_S10, ROOM_S11, ROOM_00],
	[ROOM_00, ROOM_04 , ROOM_06 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00 , ROOM_00]
]; 

//--------------------
// Quests
//--------------------

// Quest: Repair generator
let QUEST_REPAIR_GENERATOR = new Quest(0, `repair the generator in room 7`, `repair generator`, ROOM_07);
for (let x = 0; x < MAP.length; x++)
	for (let y = 0; y < MAP[x].length; y++)
		MAP[x][y].longDesc = `It is to dark to make out anything. It would probably be best to first <b>repair</b> the <b>generator</b> so the lights can be turned back on.`;
QUEST_REPAIR_GENERATOR.questdescriptions[6]		= 	`An emergency sign is glowing red on the wall. The red glow reveals 2 more sleeping pods</br> and a open door in the south to the hallway. There is a display blinking next to your sleeping pod.</br> The display keeps blinking lights.</br>`;	// ROOM 06
QUEST_REPAIR_GENERATOR.questdescriptions[7] 	= 	`An astroid has penetrated the ships armor. The hole has been automaticly repaired but the <b>generator</b> is still broken. It needs to be <b>repaired</b> manually.`; // ROOM 07
QUEST_REPAIR_GENERATOR.questdescriptions[27]	= 	`The pulsing line is going inside the south room the door is already open. On the wall next to the door glows a number, it says: R07.`; 	//ROOM_N01	
QUEST_REPAIR_GENERATOR.questdescriptions[28]	= 	`The pulsing line go's to the west. It's going inside the next room.`;// ROOM_N02
QUEST_REPAIR_GENERATOR.questdescriptions[29]	= 	`The hallway continues to the east, south and west. A red emergency sign sits on the north wall. The way to the east is completely dark. The pulsing line continues to the west.`; // ROOM_N03
QUEST_REPAIR_GENERATOR.questdescriptions[38]	= 	`The hallway leads one way. The light continues to the north.`;// ROOM_C01
QUEST_REPAIR_GENERATOR.questdescriptions[39]	= 	`The hallway leads one way. The pulsing blue line continues to the north.`;// ROOM_C02
QUEST_REPAIR_GENERATOR.questdescriptions[43]	= 	`There is a soft pulsing blue line strip on the ceiling of the hallway. To the west there is complete darkness. The blue line continues to the east hallway.`;// ROOM_S02
QUEST_REPAIR_GENERATOR.questdescriptions[44]	= 	`The hallway continues to the north, east and west. A red emergency sign sits on the south wall. The way to the east is completely dark. The pulsing line continues to the north.`;// ROOM_S03



let BROKEN_GENERATOR							= 	new Furniture(1, `generator`, ``, `The <b>generator</b> seems to be broken. There are sparks flying from a lose cable. You should probably <b>repair</b> it.`);	
QUEST_REPAIR_GENERATOR.questObjects[7]			= 	BROKEN_GENERATOR;	// ROOM_07

// Quest: Send montly information log 	&& IF THERES TIME
let QUEST_SEND_MONTHLY_LOG 		= new Quest(0, `Send the monthly log by pressing an button in room 24`, `send log`, ROOM_24);
let DESK_R01					= new Furniture(1, `desk`, `The desk is well cleaned. There is a note sticking to the display. It say's: REMINDER: send monthly log.`)


//--------------------
// Messages
//--------------------

// HUD text
let TXT_CURRENT_ROOM					=	`Current room: `;
let TXT_ROOM_DESCRIPTION				=	`Official room name: `;
let TXT_LAST_COMMAND					= 	`Last command: `;
let TXT_MOVE							=	`You moved `;
let TXT_TOWARDS							=	`Towards room: `;
let TXT_DEVIDER							=	`*><br/>`;

// In game text
let MSG_PICK_A_DIRECTION				=	`No direction given. Type "help go" for more information on the directions you are allowed to go.`;
let MSG_GET_HELP						= 	`Use "help [command]" for more information. <br/><br/> Avaiable commands: `;
let MSG_INSPECT_WHAT					=	`What would you like to inspect ? Type "inpect [room|object]" for more information.`;
let MSG_VALID_DIRECTIONS				=	`Valid directions:`;
let MSG_PATH_BLOCKED					= 	`You can't go this way.`;

let MSG_ACCEPT_TO_START					=	`It is the year 3136. The earth is full of life. Space travel has become a regular thing.</br>
											Mars has been fully populated and brought the world several new materials that made new things possible.</br>
											</br>
											True appriciation from space travel came from the company All*. This company created selfreproducing</br>
											ion-feul wich made space travel between mars even possible for common folk. </br>
											Because times are good and peacefull, All* has planned to travel between the stars. </br>
											After 40 year's they created 2500 interstellar space ships that will be sent out trough out the universe.</br>
											</br>
											-----------------------------------------------------------------------------</br>
											All* is recruiting!</br>
											</br>
											This job is for people that wan't to explorere the Universe.</br>
											For this trip all your needs will be met by our ultra futuristic space ship.</br>
											Requirements:</br>
												- You are prepared to leave everything behind.</br>
												- You accept that this may be a one way trip.</br>
												- Send a monthly log back to earth with information.</br>
											</br>
											By accepting this interstellar travel you understand and accept the</br>
											possible consecuentes.</br>
											-----------------------------------------------------------------------------</br>
											</br>
											Type "Accept" to start playing.`;
											
let MSG_INTRO							=	`You have been assigned to ship nr: 1723.</br>
											Like the other five crew mates you wen't into hypersleep after passing Venus.</br> 
											You are sleeping...</br>
											You wake up from hypersleep 7 months early.</br>
											...</br>
											The ship is dark.</br>`;
let MSG_END								=	`The generator is restored and the ship is generating power again. All the lights have turned on. </br></br>This is currently everything in the game. Have fun exploring if you want to and...</br> THANKYOU FOR PLAYING !</br>`;
											
let MSG_GAME_NOT_STARTED				=	`You have not yet accepted the contract. Type "Accept" to start playing.<br/>`;

//--------------------
// Error messages
//--------------------
let ERROR_COMMAND_NOT_FOUND 			= 	`The command you used is not reqognized. Type "help" for more information on commands.`;
let ERROR_COMMAND_NOT_CREATED 			=	`This command has not yet been programmed`;
let ERROR_DIRECTION_DOES_NOT_EXCIST 	= 	`direction does not excist`;
let ERROR_INCORRECT_VALUE				= 	`Incorrect value given. Type "help [command]" for information on a command.`;
let ERROR_INVALID_DIRECTION				=	`I never heard of that direction.`;

(function() {
	
	let inputArea = document.getElementById('input');
	
	let outputController = new OutputController();
	outputController.load();
	
	// create world.
	let game = new Game(ROOM_100);
	let cmdController = new CommandController(game);
	
	// load the game.
	game.load();
	
	// draw the intro.
	outputController.insertLine(MSG_ACCEPT_TO_START);
	
	// load the first quest.
	QUEST_REPAIR_GENERATOR.load();
	
	
	// listen for player input
	inputArea.addEventListener('keypress', function (e) {
		var key = e.keyCode;
		// if enter key is pressed
		
		if (key === 13) { 
			// check if user has accepted the contract.
			let contractAccepted = this.value.toLowerCase() === "accept";
			if(contractAccepted){
				
				game.started = true;
				
				// clear console of previous information.
				outputController.clearUserFeedback();
				
				// place player in starting room on ship
				game.player.currentRoom = ROOM_06;
				
				// print intro
				outputController.insertLine(MSG_INTRO);
				
				// print current room description
				outputController.insertLine(game.player.currentRoom.longDesc);
				
				// update the HUD
				let currentStep = game.getCurrentState(this.value.toLowerCase(), [""]);
				outputController.drawStep(currentStep);
				
				// clear user input.
				inputArea.value = "";
				
				return;
			}

			if(game.started){
				//---------------------
				// Game has started
				//---------------------
				
				// process player input
				let userFeedback = cmdController.runCommand(this.value.toLowerCase());	// expects the input of the player;
				
				
				//	repeat for all quests
				
					
				// 	check if quest is completed.
				if(!QUEST_REPAIR_GENERATOR.complete && this.value.toLowerCase() === QUEST_REPAIR_GENERATOR.keyCommand && game.player.currentRoom === QUEST_REPAIR_GENERATOR.objectiveRoom){
					// quest completed
					QUEST_REPAIR_GENERATOR.complete = true;
					
					// unload the currentQuest.
					QUEST_REPAIR_GENERATOR.unload();	
					
					// load next quest.
					//QUEST_SEND_MONTHLY_LOG.load();
					outputController.insertLine(MSG_END);
				}
				
				// write result to screen.
				let currentStep = game.getCurrentState(this.value.toLowerCase(), userFeedback);	// get 
				outputController.drawStep(currentStep);
				
				// clear input
				inputArea.value = "";
			}
			else{
				outputController.insertLine(MSG_GAME_NOT_STARTED);
				inputArea.value = "";
				return;
			}
			
		}

	});	
})();	

	
	
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console