Old
by secretgspot
HTML
<div id="critter"></div>
<div id="info"></div>
CSS
/* TODO: this should be done / confirmed w JS */
#critter {
position: relative;
margin: 20px;
}
JavaScript
// Critter by Peter Ajtai
// this is old - look at: http://jsfiddle.net/pajtai/CtwQw/
(function(window, undefined) {
var document = window.document,
Critter = function() {},
CritterP = Critter.prototype,
Utility = function() {},
UtilityP = Utility.prototype,
Default = {};
Default.meadowStyle = {
"width": "10px",
"height": "10px",
"background-color": "#000",
"position": "absolute",
"class": "meadow",
"z-index": "100"
};
Default.foodStyle = {
"width": "10px",
"height": "10px",
"background-color": "#00FF00",
"position": "absolute",
"class": "food",
"z-index": "101"
};
Default.root = "#critter";
Default.info = "#info";
/**
* Add new element.
* Element is added to the one passed in.
* CSS is styled per config.
* If a class is bundled with config, it is added too.
*/
UtilityP.div = function(config, ellie) {
var added = $("<div/>").appendTo(ellie).css(config);
if (typeof config.class !== "undefined") {
added.addClass(config.class);
}
return this;
};
UtilityP.style = function(config, ellie) {
$(ellie).css(config);
return this;
}
/**
* Returns a random integer between min and maxm inclussive
* Using Math.round() will give you a non-uniform distribution!
*/
UtilityP.getRandomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
CritterP.Utility = UtilityP;
// These settings apply across all boards
CritterP.theRoot = Default.root;
CritterP.meadowStyle = Default.meadowStyle;
CritterP.foodStyle = Default.foodStyle;
CritterP.newMeadow = function(rows, cols, config) {
var theRow, theCol,
width = parseInt(this.meadowStyle.width.slice(0, -2), 10),
...