Skip to content

Instantly share code, notes, and snippets.

@jkarnowski
Created March 31, 2016 00:13
Show Gist options
  • Save jkarnowski/23b1a0bb012ee2d70a86df2e2d44a81e to your computer and use it in GitHub Desktop.
Save jkarnowski/23b1a0bb012ee2d70a86df2e2d44a81e to your computer and use it in GitHub Desktop.
var createTree = function(){
return new Tree()
}
var Tree = function Tree(){
this.age = 0;
this.height = 0;
this.orangeCount = 0;
this.isAlive = true;
this.oranges = [];
}
var Orange = function Orange(){
this.diameter = Math.floor((Math.random() * 5) + 1);
}
Tree.prototype.grow = function(){
this.age += 1;
this.height += 10;
if (this.age >= FRUIT_BEARING_AGE){
this.makeOranges()
}
if (this.age > MAX_AGE){
this.killTree()
}
};
Tree.prototype.makeOranges = function() {
this.orangeCount = Math.floor((Math.random() * 10) + 1);
for (var i =0; i < this.orangeCount; i++){
this.oranges.push(new Orange());
}
};
Tree.prototype.killTree = function() {
this.isAlive = false;
};
Tree.prototype.dropOrange = function(){
this.orangeCount -= 1;
this.oranges.pop();
return new Orange;
};
var pickOrange = function(tree){
return tree.dropOrange()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment