Skip to content

Instantly share code, notes, and snippets.

@Paratron
Created October 16, 2014 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paratron/ca54b381bb191387bc31 to your computer and use it in GitHub Desktop.
Save Paratron/ca54b381bb191387bc31 to your computer and use it in GitHub Desktop.
Alternative constructor prototype
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