Skip to content

Commit

Permalink
Merge branch 'feat/GameEngine'
Browse files Browse the repository at this point in the history
  • Loading branch information
DLzer committed Dec 20, 2021
2 parents 96dca32 + 138b4c2 commit 9064341
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 48 deletions.
111 changes: 81 additions & 30 deletions assets/js/Domain/GameEngine/GameEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ GameEngine = {
"CLOSE", "INVENTORY", "BAG", "ZYZZY", "HELP",
"USE", "NORTH", "EAST", "SOUTH", "WEST", "MAILBOX",
"UP", "DOWN", "LEFT", "RIGHT", "SAVE", "RESET",
"HELP", "STATE", "BRIEF", "VERBOSE", "READ"
"HELP", "STATE", "BRIEF", "VERBOSE", "READ",
"CLIMB", "UP", "DOWN",
],
openableInstances: [
"WINDOW", "DOOR", "TRAPDOOR", "TRAP"
"WINDOW", "DOOR", "TRAPDOOR", "TRAP", "TREE", "KITCHEN",
"CHIMNEY",
],

/**
Expand Down Expand Up @@ -152,9 +154,18 @@ GameEngine = {

var verbMap = {
"GO": GameEngine.goAction,
"NORTH": GameEngine.goAction,
"SOUTH": GameEngine.goAction,
"EAST": GameEngine.goAction,
"WEST": GameEngine.goAction,
"BACK": GameEngine.goAction,
"CLIMB": GameEngine.goAction,
"UP": GameEngine.goAction,
"DOWN": GameEngine.goAction,
"ENTER": GameEngine.goAction,
"LOOK": GameEngine.lookAction,
"TAKE": GameEngine.takeAction,
"ENTER": GameEngine.goAction,
"USE": GameEngine.useAction,
// "PUSH": GameEngine.Push,
// "PULL": GameEngine.Pull,
"DROP": GameEngine.dropAction,
Expand All @@ -172,7 +183,11 @@ GameEngine = {
"VERBOSE": GameEngine.setVerboseOutput,
}

verbMap[ cmd ]( arg );
if ( ["NORTH", "SOUTH", "EAST", "WEST", "BACK", "CLIMB", "ENTER", "UP", "DOWN"].includes(cmd) ) {
verbMap[ cmd ]( cmd );
} else {
verbMap[ cmd ]( arg );
}

},

Expand Down Expand Up @@ -287,45 +302,49 @@ GameEngine = {
let currentRoom = GameEngine.getCurrentRoom();
let lDirection = direction.toLowerCase();

if (lDirection === undefined)
{
output.before("You can't go that way.");
}
else
{
if ( lDirection == "back" ) {
console.log("**GameEngine: Moving "+lDirection);
GameEngine.player.setCurrentLocation(GameEngine.player.getPreviousLocation());
GameEngine.player.setPreviousLocation(roomList[currentRoom].varName);
currentRoom = GameEngine.getCurrentRoom();
} else {

if ( lDirection == "back" ) {
console.log("**GameEngine: Moving "+lDirection);
GameEngine.player.setCurrentLocation(GameEngine.player.getPreviousLocation());
GameEngine.player.setPreviousLocation(roomList[currentRoom].varName);
currentRoom = GameEngine.getCurrentRoom();
} else {
console.log("**GameEngine: Moving "+lDirection);
GameEngine.player.setPreviousLocation(roomList[currentRoom].varName);
GameEngine.player.setCurrentLocation(roomList[currentRoom][lDirection].varName);
currentRoom = GameEngine.getCurrentRoom();
if (roomList[currentRoom][lDirection] === undefined)
{
GameEngine.cliOutput("You can't go that way.");
return;
}

if (GameEngine.player.getVerboseMode()){
if (currentRoom.visited) {
GameEngine.cliOutput("<strong>" + roomList[currentRoom].name + "</strong>");
GameEngine.showItems(roomList[currentRoom]);
}
else {
GameEngine.lookAction();
roomList[currentRoom].visited = true;
}
}
console.log("**GameEngine: Moving "+lDirection);
GameEngine.player.setPreviousLocation(roomList[currentRoom].varName);
GameEngine.player.setCurrentLocation(roomList[currentRoom][lDirection].varName);
currentRoom = GameEngine.getCurrentRoom();
}

if (GameEngine.player.getVerboseMode()){
if (currentRoom.visited) {
GameEngine.cliOutput("<strong>" + roomList[currentRoom].name + "</strong>");
GameEngine.showItems(roomList[currentRoom]);
}
else {
GameEngine.lookAction();
roomList[currentRoom].visited = true;
}
}

else {
GameEngine.lookAction();
roomList[currentRoom].visited = true;
}
},

openAction: (direction) => {

if ( direction == "EGG" ) {
GameEngine.useAction("EGG");
return;
}

let currentRoom = GameEngine.getCurrentRoom();

if (roomList[currentRoom]["open"] === undefined || !roomList[currentRoom]["open"])
Expand Down Expand Up @@ -417,6 +436,38 @@ GameEngine = {

},

useAction: (item) => {

if ( !item ) {
GameEngine.cliOutput("Use what?");
}

let lItem = item.toLowerCase();

if (!GameEngine.player.getPlayerInventory().includes(lItem)) {
GameEngine.cliOutput("You don't have a "+lItem+" to use!");
}

if (itemObjects[lItem].inUse) {
GameEngine.cliOutput("The item is already in use. Putting item away.");
itemObjects[lItem].inUse = false;
GameEngine.lookAction();
} else {
if ( lItem == "egg") {
GameEngine.cliOutput("<strong>"+itemObjects[lItem].openDesc+"</strong>");
if ( GameEngine.getCurrentRoom() == "tree") {
GameEngine.goAction("back");
return;
}
} else {
GameEngine.cliOutput("<strong>"+itemObjects[lItem].useDesc+"</strong>");
}
itemObjects[lItem].inUse = true;
GameEngine.lookAction();
}

},

}

$(window).on('load', function() {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/Domain/Item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var sack = new Item("sack","sack","", "elongated brown sack, smelling of h
var bottle = new Item("bottle","bottle","A glass bottle is sitting on the table containing a quantity of water.", "A glass bottle is sitting on the table containing<br />a quantity of water.","a quantity of water", false, ['open','drink'], "opened", "Thank you very much. I was rather thirsty (from all this talking, probably).<br />",false);
var leaflet = new Item("leaflet","leaflet","", "small leaflet","WELCOME TO ZORK!<br /><br />ZORK is a game of adventure, danger and low cunning.<br />In it you will explore some of the most amazing territory ever seen by mortals.<br />No computer should be without one!",false,["read"], "", "",false);
var mat = new Item("mat","mat", "A rubber mat saying 'Welcome to Zork!' lies by the door.", "A rubber mat", "", false, [], "","",false);
var egg = new Item("egg","egg", "In the birds nest is a large egg encrusted with precious jewels, apparently scavenged by a childless songbird.<br /> The egg is covered with fine golf inlay, and ornamented in lapis lazuli and mother-of-pearl.<br /> Unlike most eggs, this one is hinged and closed with a delicate looking clasp.<br /> The egg appears extremely fragile.<br />", "", false, ['use'],"You've opened the egg.<br />", "The egg glimmers, blinds you, and you fall to the ground.<br />",false);
var egg = new Item("egg","egg", "In the birds nest is a large egg encrusted with precious jewels, apparently scavenged by a childless songbird.<br /> The egg is covered with fine gold inlay, and ornamented in lapis lazuli and mother-of-pearl.<br /> Unlike most eggs, this one is hinged and closed with a delicate looking clasp.<br /> The egg appears extremely fragile.<br />", "", false, ['use'],"You've opened the egg.<br />", "The egg glimmers, blinds you, and you fall to the ground.<br />",false);
var leaves = new Item("leaves","grating","On the ground is a pile of leaves.", "","",false, ['use'], "", "You place the grating on the ground. Great..",false);
var sword = new Item("sword","elven sword","Above the trophy case hangs an elvish sword of great antiquity.", "","",false, ['use','attack'], "You pull the elven sword from you bag and hold it high in the air. It glows with a mystical aura.<br />", "You fiercly swing the sword.<br />",false);
var lantern = new Item("lantern","brass lantern","A battery-powered brass lantern is on the trophy case.", "","",false, ['use','on', 'off'], "", "The brass lantern is now on.<br />",false);
Expand Down
17 changes: 0 additions & 17 deletions assets/js/Domain/Room/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,6 @@ var roomList = {
"livingRoomRugMoved": new Room("livingRoomRugMoved", "Living Room", "With a great effort, the rug is moved to one side of the room, revealing the dusty cover of a closed trap door.",[sword, lantern], false),
"livingRoomTrapDoor": new Room("livingRoomTrapDoor", "Trap Door", "The door reluctantly opens to reveal a rickety staircase descending into darkness.",[], false),
"cellar": new Room("cellar", "Cellar", "You are in a dark and damp cellar with a narrow passageway leading north, and a crawlway to the south. On the west is the bottom of a steep metal ramp which is unclimbable.",[], true),
"southOfHouse": new Room("southOfHouse","South of House", "You are facing the south side of a white house.<br /> There is no door here, and all the windows are boarded", [], false),
"behindHouse": new Room("behindHouse","Behind House", "You are behind the white house. A path leads into the forest to the east. <br />In one corner of the house there is a small window which is slightly ajar.",[], false),
"windowBehindHouse": new Room("windowBehindHouse","Behind House", "You are behind the white house. A path leads into the forest to the east. <br />In one corner of the house there is a small window which is open.",[], false),
"kitchen": new Room("kitchen","Kitchen", "You are in the kitchen of a the white house. A table seems to have been used recently for the<br />preparation of food. A passage leads to the west and a dark staircase can be seen leading upward.<br /> A dark chimney leads down and to the east is a small window which is open.<br />",[sack, bottle], false),
"mailbox": new Room("mailbox", "Mailbox", "Opening the mailbox reveals a leaflet.",[leaflet]),
"tree": new Room("tree", "Up A Tree", "You are about 10 feet above the ground nestled among some large branches.<br />The nearest branch above you is out of reach. Besides you on the branch is a small birds nest.", [egg], false),
"northClearing": new Room("northClearing", "Clearing", "You are in a clearing, with a forest surrounding you on all sides. A path leads south.", [leaves], false),
"eastClearing": new Room("eastClearing", "Clearing", "You are in a small clearing in a well marked forest path that extends to the east and west.", [], false),
"canyonView": new Room("canyonView", "Canyon View", "You are at the top of the Great Canyon on its west wall.<br />From here there is a marvelous view of the canyon and parts of the Frigid River upstream. Across the canyon, the walls of the White Cliffs join the mighty ramparts of the Flathead Mountains to the east.<br /> Following the Canyon upstream to the north, Aragain Falls may be seen, complete with rainbow.<br /> The mighty Frigid River flows out from a great dark cavern. To the west and south can be seen an immense forest, stretching for miles around. A path leads northwest.<br > It is possible to climb down into the canyon from here.", [], false),
"rockyLedge": new Room("rockyLedge", "Rocky Ledge", "You are on a ledge about halfway up the wall of the river canyon.<br />You can see from here that the main flow from Aragain Falls twists along a passage which it is impossible for you to enter.<br />Below you is the canyon bottom. Above you is more cliff, which appears climbable.", [], false),
"canyonBottom": new Room("canyonBottom", "Canyon Bottom", "You are beneath the walls of the river canyon which may be climbable here.<br />The lesser part of the runoff of Aragain Falls flows by below. To the north is a narrow path.", [], false),
"endOfRainbow": new Room("endOfRainbow", "End of Rainbow", "You are on a small, rocky beach on the continuation of the Frigid River past the Falls.<br /> The beach is narrow due to the presence of the White Cliffs. The river canyon opens here and sunlight shines in from above.<br />A rainbow crosses over the falls to the east and a narrow path continues to the southwest.", [], false),
"chimney": new Room("chimney", "Chimney", "You are in a small cold chimney, on the wall reads 'Santa was here'.",[], true),
"livingRoom": new Room("livingRoom", "Living Room", "You are in the living room. There is a doorway to the east, a wooden door with strange gothic lettering to the west, which appears to be nailed shut, a trophy case, and a large oriental rug in the center of the room.",[sword, lantern], false),
"livingRoomRugMoved": new Room("livingRoomRugMoved", "Living Room", "With a great effort, the rug is moved to one side of the room, revealing the dusty cover of a closed trap door.",[sword, lantern], false),
"livingRoomTrapDoor": new Room("livingRoomTrapDoor", "Trap Door", "The door reluctantly opens to reveal a rickety staircase descending into darkness.",[], false),
"cellar": new Room("cellar", "Cellar", "You are in a dark and damp cellar with a narrow passageway leading north, and a crawlway to the south. On the west is the bottom of a steep metal ramp which is unclimbable.",[], true),
}
roomList.westOfHouse.visited = true;
// Forest One
Expand Down

0 comments on commit 9064341

Please sign in to comment.