lundi 25 avril 2016

Snake Game random colors

I created a snake game but i want every new block added onto it to genarate a random new color. This is what I have right now but all it does is send a "null" back and causes it to be white.

// Draw a square for each segment of the snake's body
Snake.prototype.draw = function () {
for (var i = 0; i < this.segments.length; i++) {
this.segments[i].drawSquare(randomColor());
}
};








function randomColor() {
    return '#' + ('00000' + (Math.random() * 16777216 << 0).toString(16)).substr(-6);
}



Aucun commentaire:

Enregistrer un commentaire