You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Tile.js 881B

1234567891011121314151617181920212223242526272829303132333435363738
  1. export default class Tile {
  2. constructor(x, y, name) {
  3. this.x = x;
  4. this.y = y;
  5. this.name = name;
  6. }
  7. }
  8. Tile.createLine = function(width, name, x = 0, y = 0) {
  9. if (width <= 1) {
  10. return [ new Tile(x, y, name+"-lr") ];
  11. } else {
  12. return [
  13. new Tile(x, y, name+"-l"),
  14. Array.from({ length: width - 2 }, (_, i) =>
  15. new Tile(x + i + 1, y, name)),
  16. new Tile(x + width - 1, y, name+"-r"),
  17. ];
  18. }
  19. }
  20. Tile.createBox = function(width, height, nameTop, nameMid, nameBottom) {
  21. if (height <= 1) {
  22. return Tile.createLine(width, nameTop);
  23. } else if (height <= 2) {
  24. return [
  25. Tile.createLine(width, nameTop),
  26. Tile.createLine(width, nameBottom),
  27. ];
  28. } else {
  29. return [
  30. Tile.createLine(width, nameTop),
  31. Array.from({ length: height - 2 }, (_, i) =>
  32. Tile.createLine(width, nameMid, 0, i + 1)),
  33. Tile.createLine(width, nameBottom, 0, height - 1),
  34. ];
  35. }
  36. }