blob: ebe0f9bcf82a19d823ce0e8b8f56d682cd762710 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
import { Vector2, placeOnBoard } from "./engine/visual.js"
import { board } from "./board.js"
const ASSETS_BLACK = "assets/black.png"
const ASSETS_WHITE = "assets/white.png"
export class Stone {
constructor({
team = "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 ${this.team}`
let img = document.createElement("img")
img.src = this.team == "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 = response.width
}
}
|