48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
class Levels {
|
|
load(lvl) {
|
|
let map = [];
|
|
switch (+lvl) {
|
|
case 1:
|
|
map = [].concat(
|
|
this.row(0, [1, 0, 1, 0, 0, 1, 0, 1]),
|
|
this.row(1, [1, 1, 1, 1, 1, 1, 1, 1]),
|
|
this.row(3, [0, 1, 1, 1, 1, 1, 1, 0]),
|
|
this.row(4, [1, 1, 1, 1, 1, 1, 1, 1])
|
|
);
|
|
break;
|
|
case 2:
|
|
map = [].concat(
|
|
this.row(0, [1, 1, 1, 0, 1, 1, 0, 0]),
|
|
this.row(1, [0, 0, 1, 0, 1, 0, 1, 0]),
|
|
this.row(2, [0, 0, 1, 0, 1, 0, 1, 0]),
|
|
this.row(3, [1, 0, 1, 0, 1, 0, 1, 0]),
|
|
this.row(4, [0, 1, 1, 0, 1, 1, 0, 0])
|
|
);
|
|
break;
|
|
default:
|
|
map = [].concat(
|
|
this.row(0, [1, 1, 1, 1, 1, 1, 1, 1]),
|
|
this.row(1, [1, 1, 1, 1, 1, 1, 1, 1]),
|
|
this.row(2, [1, 1, 1, 1, 1, 1, 1, 1]),
|
|
this.row(3, [1, 1, 1, 1, 1, 1, 1, 1]),
|
|
this.row(4, [1, 1, 1, 1, 1, 1, 1, 1])
|
|
);
|
|
break;
|
|
}
|
|
return this.toBricks(map);
|
|
}
|
|
|
|
row(r, bricksTypes) {
|
|
let row = [];
|
|
for (var i = 0; i < bricksTypes.length; i++) row.push([bricksTypes[i], i, r]);
|
|
return row;
|
|
}
|
|
|
|
toBricks(map) {
|
|
let bricks = [];
|
|
map.forEach(b => {
|
|
if (b[0] > 0) bricks.push(new Brick(b[0], b[1], b[2]));
|
|
});
|
|
return bricks;
|
|
}
|
|
} |