diff options
author | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-12 13:51:59 +0100 |
---|---|---|
committer | niliara-edu <nil.jimeno@estudiant.fjaverianas.com> | 2024-12-12 13:51:59 +0100 |
commit | eb460fbb161e76052b7bdd2c57afc65e2e99bc2e (patch) | |
tree | 2d8bd718d099a3c9202ac63fb9146754b07e4ef4 /src/stone.js | |
parent | fa377bcc6d4793dcd79ae5c07a43a1193aa2613a (diff) |
place pieces
Diffstat (limited to 'src/stone.js')
-rw-r--r-- | src/stone.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/stone.js b/src/stone.js new file mode 100644 index 0000000..5203fed --- /dev/null +++ b/src/stone.js @@ -0,0 +1,43 @@ +import { placeOnBoard } from "./engine/visual/placeOnBoard.js" +import { Vector2 } from "./engine/visual/vector2.js" +import { board } from "./board.js" +import { ASSETS_BLACK, ASSETS_WHITE, PLAYER } from "./constants.js" + + + +export class Stone { + constructor({ + team = PLAYER.BLACK, + position = new Vector2(0, 0), + }) { + this.team = team + this.position = position + + this.create_span() + board.stones[position.y][position.x] = this + + this.update() + } + + create_span() { + this.span = document.createElement("span") + this.span.className = `stone` + + let img = document.createElement("img") + img.src = this.team == PLAYER.BLACK ? ASSETS_BLACK : ASSETS_WHITE + this.span.appendChild(img) + + document.body.appendChild(this.span) + } + + update() { + let response = placeOnBoard({ + position: this.position, + board_size: board.size, + }) + + this.span.style.left = response.left + this.span.style.top = response.top + this.span.style.width = this.span.style.height = response.size + } +} |