Created
December 13, 2015 21:56
-
-
Save zoolu-got-rhythm/df52d76dc5b01d659892 to your computer and use it in GitHub Desktop.
This file contains 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
/* TODO: minimum viable product, is just a console.log version before a DOM version. | |
add chicken images, onamatopia's, sounds & egg spawns. | |
*/ | |
var chickPic = new Image("http://www.clker.com/cliparts/Q/7/U/E/h/1/white-chicken-hi.png"); | |
var eggPic = new Image("http://www.pd4pic.com/images/brown-food-cartoon-eggs-egg-breakfast-chicken.png"); | |
// function constructor | |
function Chicken(eggs){ | |
this.chicken = chickPic; | |
this.eggs = eggs; | |
this.egg = eggPic; | |
} | |
function Farmer(){ | |
} | |
Chicken.prototype.sound = function(){ | |
console.log("baghKURR!"); | |
} | |
// chicken simulator | |
var sim = { | |
init: function(){ | |
this.chickens = []; | |
this.weekNo = 1; | |
this.production; // number of eggs in week x | |
// check production every week | |
var self = this; | |
this.weekly = window.setInterval(function(){ | |
self.perWeek(); | |
}, 5000); | |
}, | |
spawn: function(){ | |
var randomNumber; | |
// Create a bunch of chickens. | |
for (var i = 0; i < 10; i++) { | |
randomNumber = Math.floor(Math.random() * 10); | |
this.chickens.push(new Chicken(randomNumber)); | |
this.production += randomNumber; | |
if(Math.floor(Math.random() * 2)){ | |
// this.chickens[i].sound(); | |
} | |
} | |
console.log(this.chickens); | |
}, | |
perWeek: function(x){ | |
// timer: every week check chicken production then kill chickens. | |
// reset | |
this.production = 0; | |
this.chickens.length = 0; | |
console.log("week " + this.weekNo); | |
this.weekNo++; | |
this.spawn(); | |
console.log("this week the chickens produced " + this.production + " eggs.."); | |
} | |
}; | |
sim.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment