Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandra-simeonova authored May 16, 2019
1 parent 4964589 commit 38c186e
Show file tree
Hide file tree
Showing 6 changed files with 515 additions and 2 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
# TextAdventure
Part of a school project
Text Adventure Game
==================

==================

__Working title:__ Escape from the House of Usher
(based on 'The Fall of the House of Usher' by Edgar Allan Poe)

__Opening:__ The protagonist receives a letter from a long-estranged friend who wants his company. The friend, Roderick Usher, says he is very ill and his sister is dying. The protagonist can choose whether to visit him. The game begins when (s)he arrives at Usher's house. A lot of strange things happen while (s)he is there... The protagonist needs to preserve his/her sanity and get out of the house alive.

__Setting:__ The House of Usher - a haunted Gothic house. The protagonist moves through the different rooms, as well as the tombs in the basement.

__Entities:__
*People - Protagonist, Roderick Usher, Madeline (Roderick's sister), servant
*Monsters - Madeline, ghosts
*Objects - candle, book(s), key(s), map,

__Actions:__ pick up, drop, walk, talk, open/ close door, use (item)

__Endgame scenarios:__
* not visiting Usher during the opening ends the game
* you can choose to leave the house
* the ghosts in the house can kill you/ drive you insane
* Madeline starts chasing you after she rises from the tomb & can kill you
85 changes: 85 additions & 0 deletions game.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

html {
font-family: de-walpergens-pica, serif;
text-align: center;
}

html, body {
height: 100%;
padding: 0;
margin: 0;
background-color: #484848;
}

header, main, footer, aside {
position: fixed;
}

header, footer {
width: 100%;
height: 10%;
color: #B8B8B8 ;
}

main {
top: 10%;
}

aside {
width: 20%;
color: #B8B8B8;
}

aside#help {
left: 0;
top: 10%;
height: 80%;
}

aside#health {
left: 0;
top: 47%;
height: 80%;
}

aside#inventory {
right: 0;
top: 10%;
height: 80%;
}


main {
width: 60%;
left: 20%;
text-align: center;
}

output {
display: block;
margin: 25px;
height: 65%;
padding: 5%;
border: 7px groove black;
border-radius: 0.2em;
background-color: gray;
}

output, input {
font-size: 200%;
font-family: de-walpergens-pica, serif;
border: 3px groove black;
border-radius: 0.2em;
background-color: gray;
}

main > section {
margin: 2em;
}



footer {
top: 96%;
}

60 changes: 60 additions & 0 deletions game.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype>
<html>
<head>

<title> Text Adventure Game </title>
<meta charset="UTF-8"/>
<link href="game.css" rel="stylesheet" />
<script src="game.js"></script>
<script src="locations.js"></script>
<script src="player.js"></script>
<script src='http://use.edgefonts.net/de-walpergens-pica.js'></script>
</head>
<body>

<header>
<h1> The House of Usher (not the rapper)</h1>
</header>

<main id="game">

<output id="scene">
<p id="descrip">
</p>
<p id="feedback">

</p>
<label for="input"> Type an action and press Enter </label>
</output>

<section>
<input id="input" type="text" placeholder="Enter an action here..."/>
</section>

</main>

<aside id="inventory">
<h1> Inventory </h1>
<ul>
</ul>
</aside>

<aside id="health">
<h1> Health Points </h1>
<ul>
</ul>
</aside>

<aside id="help">
<h1> Available Actions </h1>
<ul>
</ul>
</aside>

<footer>
Copyright (c) 2014 Aleksandra Simeonova. All rights reserved.
</footer>

</body>
</html>

131 changes: 131 additions & 0 deletions game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//intro function

function gameIntro() {
var para = document.querySelector ("#descrip");
para.textContent = "You decide to visit your friend Roderick (owner of the House of Usher), because his sister Madeline is gravely ill. Your goal is to get out of the house alive and find all the Edgar Allan Poe references."
var prompt = (document.querySelector("label"));
prompt.textContent = "Enter your name and press Enter."
var inputBox = document.querySelector("#input");
var listener = function(event) {
if (event.keyCode === 13) {
event.target.removeEventListener("keyup", listener);
customizePlayer(this.value);
gameStart();
}
}
inputBox.addEventListener ("keyup", listener);
};

//start game

var gameStart = function() {
var inputBox = document.querySelector("#input");
inputBox.addEventListener("keyup", function(event){
if (event.keyCode === 13) {
gameStep(this.value);
}
});
var prompt = (document.querySelector("label"));
prompt.textContent = "Type an action and press Enter."
displayActions();
healthPoints(0);
displayScene ();
}

//run one part of game

function gameStep (input){
var command = interpret (input);
var result = execute (command);
report (result);
};

//function that customizes player
function customizePlayer(input) {
player.name = input;
};

//interpret the input
function interpret (input){
var cmd = {}, tokens = input.trim().toLowerCase().split(" ");
cmd.action = tokens.shift();
cmd.target = tokens.join(" ");
return cmd;
};

//executing user's command
function execute (command){
console.log (" execute");
player[command.action](command.target);
};

//display result on page
function report (result){
displayActions();
displayInventory();
displayScene();
};

//clearing content before putting new stuff in

function clearContent(node) {
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
}

//function for displaying feedback

function displayFeedback (message) {
var message = message;
var para = document.querySelector ("#feedback");
clearContent(document.querySelector("#feedback"));
para.textContent = "\n" + message;
};

//function for displaying actions

function displayActions() {
var field, action, actionList;
actionList = document.querySelector("#help > ul");
clearContent(actionList);
for (field in player) {
if (player[field] instanceof Function) {
action = document.createElement("li");
action.textContent = field;
actionList.appendChild(action);
}
}
}

//function for displaying inventory

function displayInventory() {
var i, item, inventory;
inventory = document.querySelector("#inventory > ul");
clearContent(inventory);
for (i in player.items) {
item = document.createElement ("li");
item.textContent = player.items[i];
inventory.appendChild(item);
}
}

//function for displaying scene

function displayScene() {
var para = document.querySelector ("#descrip");
para.textContent = "You are in the " + player.currLoc.name + "-" + "\n" +
player.currLoc.description + "." + "\n" +
"The items you can take are: " + player.currLoc.items
};

//function for ending game
function gameEnd () {
addEventListener("keydown", function(event) {
if (event.keyCode == 13)
window.close();
});
}

window.onload = gameIntro;
74 changes: 74 additions & 0 deletions locations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

function Location (name, description, items, locked, enemy, secret) {
this.name = name;
this.description = description;
this.items = items;
this.locked = locked;
this.enemy = enemy;
this.secret = secret;
};

var map = {
locations: [
new Location ("garden", "it is full of weeds and dead trees. You can go to the entrance", ["worm"], false, false, false),
new Location ("entrance", "a narrow corridor. You can go to the garden, dining room or living room", ["no items"], false, false, false),
new Location ("living room", "a room with a fireplace. You can go back to the entrance", ["no items"], false, false, true),
new Location ("dining room", "a room with a a large mahogany table. You can go to the study, bedroom or entrance", ["no items"], false, false, false),
new Location ("study", "a small study. Roderick sits on a chair, looking gloomy. You can go to the guest room or dining room", ["tombs key"], false, false, false),
new Location ("bedroom", "a small bedroom. You see Madeline in bed, she says 'DO NOT TAKE THE SWORD'. You can go to the tombs or the dining room", ["sword"], false, false, false),
new Location ("guest room", "a room with a wooden floor and a bed with bloodstained sheets. You can go to the study", ["tell tale heart"], true, false, true),
new Location ("tombs", "damp corridors in the basement. A stone coffin is in front of you. You can go to the bedroom", ["guest room key"], true, true, false)
],
connections:[
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0]
]
};


//connecting & disconnecting functions
function connect(map,from, to) {
map.connections[from][to] = 1;
map.connections[to][from] = 1;
}

function disconnect(map, from, to) {
map.connections[from][to] = 0;
map.connections[to][from] = 0;
}

//connecting locations
connect (map, 0, 1);
connect (map, 1, 2);
connect (map, 1, 3);
connect (map, 3, 4);
connect (map, 3, 5);
connect (map, 4, 6);
connect (map, 5, 7);

//function for seeing if item is inside locations

Location.prototype.has = function(item) {
return this.items.indexOf(item)>=0;
}


//function for removing items from location
Location.prototype.remove = function(item) {
var itemNum = this.items.indexOf(item);
if (itemNum>= 0) {
this.items.splice(itemNum, 1);
}
};

//function for adding items to location
Location.prototype.put = function(item) {
this.items.push(item);
}

Loading

0 comments on commit 38c186e

Please sign in to comment.