Created
October 16, 2014 17:01
-
-
Save Paratron/ca54b381bb191387bc31 to your computer and use it in GitHub Desktop.
Alternative constructor prototype
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
var Door = function Door(){ | |
}; | |
Door.prototype = { | |
constructor: Door, | |
name: 'Door', | |
hp: 5, | |
char: '+', | |
color: 'yellow', | |
consoleColor: 'yellow', | |
charStrokeColor: '#000', | |
charStrokeWidth: 2, | |
pushable: false, | |
passable: false, | |
blocksLos: true, | |
closed: true, | |
testAction: function(actionName, source, settings){ | |
if(!this.actions[actionName]){ | |
return false; | |
} | |
return this.actions[actionName].test.call(this, source, settings); | |
}, | |
executeAction: function(actionName, source, settings){ | |
if(this.testAction(actionName, source, settings)){ | |
return this.actions[actionName].execute.call(this, source, settings); | |
} | |
}, | |
actions: { | |
open: { | |
test: function(source, settings){ | |
return this.closed; | |
}, | |
execute: function(){ | |
this.passable = true; | |
this.blocksLos = false; | |
this.char = "'"; | |
return true; | |
} | |
}, | |
close: { | |
test: function(source, settings){ | |
return !this.closed; | |
}, | |
execute: function(source, settings){ | |
this.passable = false; | |
this.blocksLos = true; | |
this.char = "+"; | |
return true; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment