// Top-Down View
var god; // Morgan Freeman
var earth; // Brave New World
var bruceNolan; // Jim Carrey
// In the beginning...
function bigBang() {
if (god == undefined) {
var image = document.getElementById("earthlyDelights");
god = new God("God", undefined);
alert("Let there be light!");
bruceNolan = new God("Bruce", god);
earth = new World("Brave New World", bruceNolan);
image.setAttribute("style", "display:inline");
}
else {
alert("Been there, done that.");
}
}
// God
function God(name, origin) {
Thing.call(this, name, origin);
this.setNickName(name + " Almighty");
}
God.prototype = Object.create(Thing.prototype);
God.prototype.isA = function() {
return "God";
}
God.prototype.makeMan = function(name) {
return new Person(name, this)
}
God.prototype.makeWoman = function(name, man) {
return new Person(name, man.getRib());
}
// Person
function Person(name, origin) {
Thing.call(this, name, origin);
}
Person.prototype = Object.create(Thing.prototype);
Person.prototype.isA = function() {
return "Person";
}
Person.prototype.getRib = function() {
var rib = new BodyPart("rib", this);
if (this.missingRibs == undefined) {
this.missingRibs = [];
}
this.missingRibs.push(rib);
return rib;
}
// BodyPart
function BodyPart(name, origin) {
Thing.call(this, name, origin);
}
BodyPart.prototype = Object.create(Thing.prototype);
BodyPart.isA = function() {
return "Body Part";
}
// World
function World(name, origin) {
Thing.call(this, name, origin);
this.firstPerson = god.makeMan("Adam Sandler");
this.secondPerson = god.makeWoman("Eva Longoria", this.firstPerson)
}
World.prototype = Object.create(Thing.prototype);
World.prototype.isA = function() {
return "World";
}
// Thing
function Thing(name, origin) {
var nickName = undefined;
var dateOfCreation = new Date;
this.getName = function() {
return name;
}
this.whereFrom = function() {
return origin;
}
this.createDate = function() {
return dateOfCreation;
}
this.getNickName = function() {
return nickName;
}
this.setNickName = function(name) {
nickName = name;
}
}
Thing.prototype = {
isA: function() {
return "Thing";
}
}
// Magic
function specialisRevelio(id) {
var magic = document.getElementById(id);
magic.setAttribute("style", "display:inline");
toggleSpellButton("showMagicButton");
toggleSpellButton("hideMagicButton");
console.log("god:");
console.log(god);
console.log("bruceNolan:");
console.log(bruceNolan);
console.log("earth:");
console.log(earth);
}
function obliviate(id) {
var image = document.getElementById("earthlyDelights");
image.setAttribute("style", "display:none");
god = undefined;
var magic = document.getElementById(id);
magic.setAttribute("style", "display:none");
toggleSpellButton("showMagicButton");
toggleSpellButton("hideMagicButton");
}
function toggleSpellButton(id) {
var button = document.getElementById(id);
if ("display:none" == button.getAttribute("style")) {
button.setAttribute("style", "display:inline");
}
else {
button.setAttribute("style", "display:none");
}
}