Created
August 18, 2015 15:36
-
-
Save alxjrvs/cd52f5179490abfc3314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var launchpad; | |
var ship; | |
var crewConstructor; | |
var crewNames; | |
var loadCrew; | |
var rocket; | |
var countdown; | |
launchpad = function(ship, crewArray, propulsion) { | |
console.log("tray tables UP!"); | |
console.log("You are aboard the " + ship.name + "!"); | |
loadCrew(crewArray, crewConstructor, ship); | |
console.log("Your captain for this journey will be: " + ship.captain().name + "."); | |
ship.mountPropulsion(propulsion); | |
ship.fuelShip(1000000); | |
countdown(10, ship); | |
}; | |
ship = { | |
name: "Millennium Falcon", | |
crew: [], | |
propulsion: null, | |
mountPropulsion: function(propulsion){ | |
console.log('Now Mounting: ' + propulsion.type + "!"); | |
this.propulsion = propulsion; | |
}, | |
fuelShip: function(fuelAmount){ | |
console.log("Adding " + fuelAmount + " fuel to tanks..."); | |
this.propulsion.fuel += fuelAmount; | |
}, | |
captain: function(){ | |
var captain = this.crew[Math.floor(Math.random()*this.crew.length)]; | |
return captain; | |
}, | |
takeoff: function(){ | |
console.log("Taking off..."); | |
this.propulsion.fire(); | |
console.log("PSCHOOOOOOOOOOO!"); | |
} | |
}; | |
rocket = { | |
type: "rocket", | |
fuel: 0, | |
fire: function(){ | |
if (this.fuel > 0) { | |
this.fuel-- ; | |
console.log("Fuel level: " + this.fuel); | |
} | |
else { | |
console.log("WARNING: No Fuel!") | |
} | |
} | |
}; | |
crewConstructor = function(name){ | |
return { name: name }; | |
}; | |
crewNames = ["Justin", "Ian", "Ali", "Michael", "Corrin", "Jeremy", "Linghan", "Haile", "Casey", "Christina", "Alex"]; | |
loadCrew = function(crew, construct, ship){ | |
for(var i = 0; i < crew.length; i++){ | |
var crewmate = construct(crew[i]); | |
ship.crew.push(crewmate); | |
} | |
console.log("Crew has been loaded!"); | |
}; | |
countdown = function(num, ship){ | |
if( num > 0){ | |
setTimeout(function(){ | |
console.log(num); | |
countdown(num - 1, ship); | |
}, 1000); | |
}else{ | |
console.log("Blastoff!!"); | |
ship.takeoff(); | |
}; | |
if (num == 3){ | |
console.log("Ignition...") | |
}; | |
}; | |
launchpad(ship, crewNames, rocket); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment