Created
April 20, 2011 03:39
-
-
Save robotlolita/930286 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function Mage(name) { | |
this.name = name | |
} | |
Mage.prototype = function() { | |
return { cast: cast | |
, meditate: meditate } | |
function cast(spell, can) { | |
if (can) return this.name + " cast " + spell | |
else return "Nothing happens!" | |
} | |
function meditate() { | |
return "You start meditatin... zzz" | |
} | |
}() | |
inherit(Apprentice, Mage.prototype) | |
function Apprentice(name) { | |
upper(this, "constructor", name) | |
} | |
extend(Apprentice.prototype, function() { | |
return { cast: cast } | |
function cast(spell, can) { | |
return upper(this, "cast", spell, can || Math.random() < 0.5) | |
} | |
}()) | |
inherit(Sorcerer, Apprentice.prototype) | |
function Sorcerer(name) { | |
upper(this, "constructor", "Mighty " + name) | |
} | |
extend(Sorcerer.prototype, function() { | |
return { cast: cast } | |
function cast(spell) { | |
return upper(this, "cast", spell, true) | |
} | |
function meditate() { | |
return "...Your magic has increased!" | |
} | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment