Advertisement
LukeSavefrogs

Untitled

Jan 28th, 2024
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Brick {
  2.   constructor(x, y, color="", width=120, height=60) {
  3.     this.x = x;
  4.     this.y = y;
  5.     this.color = color;
  6.     this.width = width;
  7.     this.height = height;
  8.   }
  9.  
  10.   draw() {
  11.     brick.beginPath();
  12.     brick.rect(this.x, this.y, this.width, this.height);
  13.     brick.fillStyle = this.color;
  14.     brick.fill();
  15.   }
  16. }
  17.  
  18. class BrickLine {
  19.   constructor(bricks, color="") {
  20.     this.bricks = bricks;
  21.    
  22.     if (color != "") {
  23.       this.bricks.forEach(brick => brick.color = color);
  24.     }
  25.   }
  26.  
  27.   draw() {
  28.     this.bricks.forEach(brick => brick.draw());
  29.   }
  30. }
  31.  
  32. class BrickWall {
  33.   constructor(lines) {
  34.     this.lines = lines;
  35.   }
  36.  
  37.   draw() {
  38.     this.lines.forEach(line => line.draw());
  39.   }
  40. }
  41.  
  42.  
  43.  
  44. const wall = new BrickWall([
  45.   new BrickLine([
  46.     new Brick(10, 100),
  47.     new Brick(140, 100),
  48.     new Brick(270, 100),
  49.     new Brick(400, 100)
  50.   ], "yellow"),
  51.   new BrickLine([
  52.     new Brick(10, 170),
  53.     new Brick(140, 170),
  54.     new Brick(270, 170),
  55.     new Brick(400, 170)
  56.   ], "green"),
  57.   new BrickLine([
  58.     new Brick(10, 240),
  59.     new Brick(140, 240),
  60.     new Brick(270, 240),
  61.     new Brick(400, 240)
  62.   ], "orange"),
  63.   new BrickLine([
  64.     new Brick(10, 310),
  65.     new Brick(140, 310),
  66.     new Brick(270, 310),
  67.     new Brick(400, 310)
  68.   ], "red")
  69. ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement