Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Brick {
- constructor(x, y, color="", width=120, height=60) {
- this.x = x;
- this.y = y;
- this.color = color;
- this.width = width;
- this.height = height;
- }
- draw() {
- brick.beginPath();
- brick.rect(this.x, this.y, this.width, this.height);
- brick.fillStyle = this.color;
- brick.fill();
- }
- }
- class BrickLine {
- constructor(bricks, color="") {
- this.bricks = bricks;
- if (color != "") {
- this.bricks.forEach(brick => brick.color = color);
- }
- }
- draw() {
- this.bricks.forEach(brick => brick.draw());
- }
- }
- class BrickWall {
- constructor(lines) {
- this.lines = lines;
- }
- draw() {
- this.lines.forEach(line => line.draw());
- }
- }
- const wall = new BrickWall([
- new BrickLine([
- new Brick(10, 100),
- new Brick(140, 100),
- new Brick(270, 100),
- new Brick(400, 100)
- ], "yellow"),
- new BrickLine([
- new Brick(10, 170),
- new Brick(140, 170),
- new Brick(270, 170),
- new Brick(400, 170)
- ], "green"),
- new BrickLine([
- new Brick(10, 240),
- new Brick(140, 240),
- new Brick(270, 240),
- new Brick(400, 240)
- ], "orange"),
- new BrickLine([
- new Brick(10, 310),
- new Brick(140, 310),
- new Brick(270, 310),
- new Brick(400, 310)
- ], "red")
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement