class Game {
constructor(){
// 每格寬為 26px
this.blockWidth = 26;
// 格與格之間間距 2px
this.blockSpace = 2;
// 總共鋪設 20 格
this.blocks = 20;
// init
this.init();
}
init(){
// set canvas
this.canvas = document.getElementById('canvasSnake');
this.canvas.width = this.blockWidth * this.blocks + this.blockSpace * (this.blocks - 1);
this.canvas.height = this.canvas.width;
this.ctx = this.canvas.getContext('2d');
// render canvas view
this.render();
};
render(){
// bg
this.ctx.fillStyle = '#dbe3c5';
this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.width);
// 鋪設 blocks
for (var bX = 0; bX < this.blocks; bX++) {
for (var bY = 0; bY < this.blocks; bY++) {
this.drawBlock(new Vector(bX, bY), '#ced6b8')
};
};
}
};
今天筆記到這,如果內容有出入,都在麻煩糾正了,謝謝您 ε= ᕕ( ᐛ )ᕗ