From b06cac2f69ac0920ccb833176d110d285449486b Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 8 Mar 2018 19:08:58 -0500 Subject: [PATCH] Creating the project --- .jshintrc | 6 ++++++ feast.css | 4 ++++ feast.html | 35 +++++++++++++++++++++++++++++++++++ feast.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ world.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 142 insertions(+) create mode 100644 .jshintrc create mode 100644 feast.css create mode 100644 feast.html create mode 100644 feast.js create mode 100644 world.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..19ecf62 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,6 @@ +{ + "indent": 1, + "esversion": 6, + "node": true, + "sub": true +} diff --git a/feast.css b/feast.css new file mode 100644 index 0000000..aa70e3b --- /dev/null +++ b/feast.css @@ -0,0 +1,4 @@ +.compass-button { + width: 100px; + height: 100px; +} diff --git a/feast.html b/feast.html new file mode 100644 index 0000000..b531743 --- /dev/null +++ b/feast.html @@ -0,0 +1,35 @@ + + + + + + Feast + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + +
+ + + +
+ diff --git a/feast.js b/feast.js new file mode 100644 index 0000000..7a3d279 --- /dev/null +++ b/feast.js @@ -0,0 +1,49 @@ +let currentRoom = null; + +function updateDisplay() { + document.getElementById("location").innerHTML = currentRoom.name; +} + +function move(direction) { + let target = currentRoom.exits[direction]; + if (target == null) { + alert("Tried to move to an empty room!"); + return; + } else { + updateDisplay(); + } + +} + +window.addEventListener('load', function(event) { + loadCompass(); + currentRoom = createWorld(); + updateDisplay(); +}); + +function loadCompass() { + document.getElementById("compass-north-west").addEventListener("click", function() { + move(NORTH_WEST); + }); + document.getElementById("compass-north").addEventListener("click", function() { + move(NORTH); + }); + document.getElementById("compass-north-east").addEventListener("click", function() { + move(NORTH_EAST); + }); + document.getElementById("compass-west").addEventListener("click", function() { + move(WEST); + }); + document.getElementById("compass-east").addEventListener("click", function() { + move(EAST); + }); + document.getElementById("compass-south-west").addEventListener("click", function() { + move(SOUTH_WEST); + }); + document.getElementById("compass-south").addEventListener("click", function() { + move(SOUTH); + }); + document.getElementById("compass-south-east").addEventListener("click", function() { + move(SOUTH_EAST); + }); +} diff --git a/world.js b/world.js new file mode 100644 index 0000000..c32d491 --- /dev/null +++ b/world.js @@ -0,0 +1,48 @@ +"use strict"; + +let NORTH = 0; +let NORTH_EAST = 1; +let EAST = 2; +let SOUTH_EAST = 3; +let SOUTH = 4; +let SOUTH_WEST = 5; +let WEST = 6; +let NORTH_WEST = 7; + +/*jshint browser: true*/ +/*jshint devel: true*/ + +function Location(name="Nowhere") { + this.name = name; + this.exits = [null,null,null,null,null,null,null,null]; +} + +function opposite(direction) { + return (direction + 4) % 8; +} + +function connectLocations(loc1,loc2,loc1Exit) { + if (loc1.exits[loc1Exit] != null) { + alert(loc1.name + " is already connected to " + loc1.exits[loc1Exit].name); + return; + } else if (loc2.exits[opposite(loc1Exit)] != null) { + alert(loc2.name + " is already connected to " + loc2.exits[opposite(loc1Exit)].name); + return; + } else { + if (loc1Exit >= 0 && loc1Exit <= 7) { + loc1.exits[loc1Exit] = loc2; + loc2.exits[opposite(loc1Exit)] = loc1; + } + } +} + +function createWorld() { + let bedroom = new Location("Bedroom"); + let bathroom = new Location("Bathroom"); + let livingroom = new Location("Living Room"); + + connectLocations(bedroom,bathroom,EAST); + connectLocations(bedroom,livingroom,NORTH); + + return bedroom; +}