Skip to content

Commit 267b0de

Browse files
Christopher Straussh908714124
Christopher Strauss
authored andcommitted
show last move marker
1 parent 05c0ce3 commit 267b0de

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/main/client/src/Game.jsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ const TAU = 2 * Math.PI
4040
export const Game = () => {
4141
let [cursor_x, setCursor_x] = useState(-1)
4242
let [cursor_y, setCursor_y] = useState(-1)
43+
let lastStoneXref = useRef(-1)
44+
let lastStoneYref = useRef(-1)
4345
let [zoom, setZoom] = useState(0)
4446
let { gameId } = useParams()
4547
let stompClient = useContext(StompContext)
@@ -73,11 +75,7 @@ export const Game = () => {
7375
}
7476
let hoshis = new PointList(dim)
7577
if (dim === 9) {
76-
hoshis.add(2, 2)
77-
hoshis.add(2, 6)
7878
hoshis.add(4, 4)
79-
hoshis.add(6, 2)
80-
hoshis.add(6, 6)
8179
} else if (dim === 13) {
8280
hoshis.add(3, 3)
8381
hoshis.add(3, 9)
@@ -109,6 +107,8 @@ export const Game = () => {
109107
stoneRadius: getRadius(step * 0.475),
110108
territoryRadius: getRadius(step * 0.125),
111109
hoshiRadius: getRadius(step * 0.0625),
110+
lastStoneXref: lastStoneXref,
111+
lastStoneYref: lastStoneYref,
112112
}
113113
}, [board.length, canvasRef, zoom])
114114
let onMouseMove = useCallback((e) => {
@@ -148,6 +148,8 @@ export const Game = () => {
148148
return
149149
}
150150
}
151+
lastStoneXref.current = cursor_x
152+
lastStoneYref.current = cursor_y
151153
stompClient.publish({
152154
destination: "/app/game/move",
153155
body: JSON.stringify({
@@ -247,6 +249,26 @@ function showStone({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
247249
ctx.fill()
248250
}
249251

252+
function showTriangle({ isCursorInBounds, canvasRef, grid, stoneRadius, lastStoneXref, lastStoneYref }, board) {
253+
let grid_x = lastStoneXref.current
254+
let grid_y = lastStoneYref.current
255+
if (!isCursorInBounds(grid_x, grid_y)) {
256+
return
257+
}
258+
let { color } = board[grid_y][grid_x]
259+
let style = color === BLACK ?
260+
"rgba(255,255,255)" :
261+
"rgba(0,0,0)"
262+
let [x, y] = grid[grid_y][grid_x]
263+
let ctx = canvasRef.current.getContext("2d")
264+
ctx.fillStyle = style
265+
ctx.beginPath()
266+
ctx.moveTo(x, y)
267+
ctx.lineTo(x + stoneRadius, y)
268+
ctx.lineTo(x , y + stoneRadius)
269+
ctx.fill()
270+
}
271+
250272
function showShadow({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
251273
let [x, y] = grid[grid_y][grid_x]
252274
let ctx = canvasRef.current.getContext("2d")
@@ -306,6 +328,7 @@ function paintStones(context, board) {
306328
}
307329
}
308330
}
331+
showTriangle(context, board)
309332
}
310333

311334
function paintStonesCounting(context, board, countingGroup) {

0 commit comments

Comments
 (0)