2
我创建了一个蛇游戏,但我希望每一个新的块添加到它来genarate随机新颜色。这是我现在所拥有的,但它所做的只是发回一个“空白”,并使其变为白色。蛇游戏随机颜色
// 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);
}