Files
tetris.js/js/arena.js
Marcel 06a2e582fd Major rework of basic game code - pre-work for multiplayer
Includes automatic generation of required HTML elements and better responsiveness
2019-07-18 11:49:06 +02:00

31 lines
839 B
JavaScript

class Arena {
constructor(gameInfo, game) {
this.g = gameInfo;
this.game = game;
this.p = this.g.player;
this.field = createMatrix(this.g.fieldSize.x, this.g.fieldSize.y);
}
clearScreen() {
this.g.context.clearRect(0, 0, this.g.canvas.width, this.g.canvas.height);
}
sweep() {
let rowCount = 1;
outer: for (let y = this.field.length - 1; y > 0; --y) {
for (let x = 0; x < this.field[y].length; ++x) {
if (this.field[y][x] === 0) {
continue outer;
}
}
const row = this.field.splice(y, 1)[0].fill(0);
this.field.unshift(row);
++y;
this.p.score += rowCount * 20;
rowCount *= 2;
}
this.game.drawArena();
}
}