1234567891011121314151617181920212223242526272829303132333435363738 |
- export default class Tile {
- constructor(x, y, name) {
- this.x = x;
- this.y = y;
- this.name = name;
- }
- }
-
- Tile.createLine = function(width, name, x = 0, y = 0) {
- if (width <= 1) {
- return [ new Tile(x, y, name+"-lr") ];
- } else {
- return [
- new Tile(x, y, name+"-l"),
- Array.from({ length: width - 2 }, (_, i) =>
- new Tile(x + i + 1, y, name)),
- new Tile(x + width - 1, y, name+"-r"),
- ];
- }
- }
-
- Tile.createBox = function(width, height, nameTop, nameMid, nameBottom) {
- if (height <= 1) {
- return Tile.createLine(width, nameTop);
- } else if (height <= 2) {
- return [
- Tile.createLine(width, nameTop),
- Tile.createLine(width, nameBottom),
- ];
- } else {
- return [
- Tile.createLine(width, nameTop),
- Array.from({ length: height - 2 }, (_, i) =>
- Tile.createLine(width, nameMid, 0, i + 1)),
- Tile.createLine(width, nameBottom, 0, height - 1),
- ];
- }
- }
|