/*Downloaded from https://www.codeseek.co/1Acid/javascript-game-pbwmZJ */
var main = function(){
var pockets = ["gum"];
var pockets_max = 4;
var backpack = [];
var backpack_max = 8;
var cockpit =["broken radio", "broken glasses"];
var fuselage = ["coke", "candy bar", "matches"];
var plane_path = ["water", "baseball cap"];
var woods_path = [];
var area = function(items, direction1, direction2, text){
this.items = items;
this.direction1 = direction1;
this.direction2 = direction2;
this.text = text;
};
var fuselage_area = new area(fuselage, cockpit_area, plane_path, "<li>Fuselage text</li>");
var cockpit_area = new area(cockpit, fuselage_area, plane_path, "<li>Cockpit area text</li>");
var plane_path_area = new area(plane_path, cockpit_area, woods_area, "<li>plane path area text</li>");
var woods_area = new area(woods_path, cockpit_area, woods_area, "<li>woods area text</li>");
// This function will display the items you are holding
var display = function(){
if(backpack.length > 0){
$(".comments").prepend("<li>Pockkets: "+ pockets + "</li>");
$(".comments").prepend("<li>Backpack: "+ backpack + "</li>");
}
else{
$(".comments").prepend("<li>Pockkets: "+ pockets + "</li>");
};
};
// This function checks to see if the pickup location contains the item you wish to pickup
var check_contain = function(array, item){
var count = array.length;
for(i=0; i< count; i++){
if(array[i] === item){
//alert("True");
return true;
};
};
return false;
};
//function to drop an item - Takes in two parameters, the item you want to drop and the location you are dropping it to
var drop = function(item, drop_location){
//check if the item is in the pockets
if (check_contain(pockets, item))
{
//find the length of the array of the drop location
var x = drop_location.length;
//add the dropped item into the last position of the drop locations array
drop_location[x] = item;
//find the index of the dropped item from the storage location and remove it from that array
var index = pockets.indexOf(item);
pockets.splice(index, 1);
return drop_location;
}
//check to see if the item is in the packpack and available to drop
else if (check_contain(backpack, item)){
//find the length of the array of the drop location
var x = drop_location.length;
//add the dropped item into the last position of the drop locations array
drop_location[x] = item;
//find the index of the dropped item from the storage location and remove it from that array
var index = backpack.indexOf(item);
pockets.splice(index, 1);
return drop_location;
};
};
//function to check if pockets is full
var pockets_space = function(){
if(pockets.length< 5){
return true;
}
else{
return false;
};
};
//function to check if backpack is full
var backpack_space = function(){
if(backpack.length < 9){
return true;
}
else{
return false;
};
};
//the pick function should allow you to take a item from 1 locations array and add it to one of your storage array
//Location is the place you are picking the item up from
//drop_item is the item you are removing from pocket/backpack
//pickup item is the item you are picking up and adding your pocket/backpack
var pick = function(pickup_item, location){
if (check_contain(location, pickup_item) === true){
//check if there is space in the pockets to store the item
if(pockets_space()){
//find the end of the array
var x = pockets.length;
//add the pickup_tem to the pockets array
pockets[x] = pickup_item;
//need to remove pickup_item from location
var index = location.indexOf(pickup_item);
//this should delete the picked up item from the pickup locations array
location.splice(index, 1);
return location;
//display message stating item was succesfully stored in pocket
$(".comments").prepend("<li>You picked up: "+ pickup_item +"</li>");
}
//if no space in pockets, is there space in the backpack?
else if(backpack_space()){
//find the end of the array
var x = backpack.length;
//add the pickup it to the backpack
backpack[x] = pickup_item;
//need to remove pickup_item from location
var index = location.indexOf(pickup_item);
//this should delete the picked up item from the pickup locations array
location.splice(index, 1);
return location;
//display message stating item was succesfully stored in backpack
$(".comments").prepend("<li>You picked up: "+ pickup_item +"</li>");
};
}
else{
$(".comments").prepend("<li>This item is not available for pickup: "+ pickup_item +"</li>");
};
return false;
};
//test
/*
check_contain(fuselage,"coke");
pick("coke", fuselage);
alert("You have the following items in your pocket: "+ pockets);
alert("the following items are available at this location: "+ fuselage);
drop("gum", fuselage);
alert("You have the following items in your pocket: "+ pockets);
alert("the following items are available at this location: "+ fuselage);
TEST WORKS!!
*/
var intro = function(){
var i = 0;
$(".comments").prepend("<li>Welcome to my game....</li>");
$("#proceed").on('click',function(){
if (i == 0) {
//add message1
$(".comments").prepend("<li>Imagine this... You are flying over the Amazon rain forest in a small twin engine aeroplane. Suddenly there is some turbulence, the engines malfunctionand the plane begins to decent extremely quickly. The pilot tells you and the other passengers to brace for a crash landing.</li>");
i++;
//$("html").css("background", "url(http://orig06.deviantart.net/43b5/f/2008/253/1/6/mayday_by_andreewallin.jpg) no-repeat center center fixed ");
}
else if (i == 1) {
//add message 2
$(".comments").prepend("<li>The pilot tries his best, but the plane is going to crash. As you decend into the forest, it us utter chaos as the wings hit the tops of trees, eventually breaking off. The plane shoots through the forest like a comet falling from the sky.<br>The Crash landing is extremely rough, and you loose conciousness</li>");
i++;
}
else if (i == 2) {
//add message 3
$(".comments").prepend("<li>You wake up a few hours later, the smell of gasoline, smoke and debris litter the immediate area. You realize you are the only survivor and the plane has been broken into three pieces, The cockpit, the fuselage and the tail section. You are bleeding but you are alive and you will survive if you can get out of the forest and back to civilisation.</li>");
i++;
}
else if(i ==3) {
//add message 4
$(".comments").prepend("<li>This is where your journey begins in the fuselage, you need to figure out how you will get back and survive...</li>");
i++;
}
else if(i ==4) {
//add message 5
$(".comments").prepend("<li>You are able to pickup and drop items, by typing either 'pick up XYZ' or 'drop XYZ'. You will need varoius items to help you get out of the forest. If you drop and item, it will be available in that same spot later. You can only fit four items in your pockets at a time, and you will need to find a storage device to increase you storage ability</li>");
//$("html").css("background", "url(https://s-media-cache-ak0.pinimg.com/originals/c1/30/3b/c1303b2099e0589e6e2029823282a6ab.jpg) no-repeat center center fixed ");
i++;
}
else if(i ==5) {
//add message 6
$(".comments").prepend("<li>You should meet and interact with varoius characters on your journey who can assist you in different ways and may require different tasks from you</li>");
i++;
}
else if(i ==6) {
//add message 7
$(".comments").prepend("<li>You have the following items on you:"+ pockets +"</li>");
i++;
}
else if(i===7){
game_start();
};
return false;
});
};
//this is the start of the game
var game_start = function(){
var still_playing = true;
var currentArea = fuselage_area;
while (still_playing){
$(".comments").prepend("<li>You have the following items on you:"+ currentArea.items +"</li>");
$(".comments").prepend(currentArea.text);
};
return false;
};
intro();
};
$(document).ready(main());