From eb460fbb161e76052b7bdd2c57afc65e2e99bc2e Mon Sep 17 00:00:00 2001 From: niliara-edu Date: Thu, 12 Dec 2024 13:51:59 +0100 Subject: place pieces --- src/link.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/link.js (limited to 'src/link.js') diff --git a/src/link.js b/src/link.js new file mode 100644 index 0000000..7d10413 --- /dev/null +++ b/src/link.js @@ -0,0 +1,57 @@ +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" +import { Stone } from "./stone.js" +import { nextTurn, turn } from "./engine/turns.js" + + + +export class Link { + constructor({ + position = new Vector2(0, 0), + }) { + this.team = turn + this.position = position + + this.createSpan() + board.links[position.y][position.x] = this + + this.span.addEventListener("click", _ => { + new Stone({ + position: position, + team: this.team + }) + nextTurn() + }); + + this.update() + } + + createSpan() { + this.span = document.createElement("span") + this.span.className = `link` + + 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, + use_real_size: true, + }) + + this.span.style.left = response.left + this.span.style.top = response.top + this.span.style.width = this.span.style.height = response.size + } + + removeLink() { + this.span.remove() + } +} -- cgit v1.2.3