Skip to content

show last move marker #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions src/main/client/src/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const TAU = 2 * Math.PI
export const Game = () => {
let [cursor_x, setCursor_x] = useState(-1)
let [cursor_y, setCursor_y] = useState(-1)
let lastStoneXref = useRef(-1)
let lastStoneYref = useRef(-1)
let [zoom, setZoom] = useState(0)
let { gameId } = useParams()
let stompClient = useContext(StompContext)
Expand Down Expand Up @@ -73,11 +75,7 @@ export const Game = () => {
}
let hoshis = new PointList(dim)
if (dim === 9) {
hoshis.add(2, 2)
hoshis.add(2, 6)
hoshis.add(4, 4)
hoshis.add(6, 2)
hoshis.add(6, 6)
} else if (dim === 13) {
hoshis.add(3, 3)
hoshis.add(3, 9)
Expand Down Expand Up @@ -109,6 +107,8 @@ export const Game = () => {
stoneRadius: getRadius(step * 0.475),
territoryRadius: getRadius(step * 0.125),
hoshiRadius: getRadius(step * 0.0625),
lastStoneXref: lastStoneXref,
lastStoneYref: lastStoneYref,
}
}, [board.length, canvasRef, zoom])
let onMouseMove = useCallback((e) => {
Expand Down Expand Up @@ -148,6 +148,8 @@ export const Game = () => {
return
}
}
lastStoneXref.current = cursor_x
lastStoneYref.current = cursor_y
stompClient.publish({
destination: "/app/game/move",
body: JSON.stringify({
Expand Down Expand Up @@ -247,6 +249,26 @@ function showStone({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
ctx.fill()
}

function showTriangle({ isCursorInBounds, canvasRef, grid, stoneRadius, lastStoneXref, lastStoneYref }, board) {
let grid_x = lastStoneXref.current
let grid_y = lastStoneYref.current
if (!isCursorInBounds(grid_x, grid_y)) {
return
}
let { color } = board[grid_y][grid_x]
let style = color === BLACK ?
"rgba(255,255,255)" :
"rgba(0,0,0)"
let [x, y] = grid[grid_y][grid_x]
let ctx = canvasRef.current.getContext("2d")
ctx.fillStyle = style
ctx.beginPath()
ctx.moveTo(x, y)
ctx.lineTo(x + stoneRadius, y)
ctx.lineTo(x , y + stoneRadius)
ctx.fill()
}

function showShadow({ canvasRef, grid, stoneRadius }, grid_x, grid_y, style) {
let [x, y] = grid[grid_y][grid_x]
let ctx = canvasRef.current.getContext("2d")
Expand Down Expand Up @@ -306,6 +328,7 @@ function paintStones(context, board) {
}
}
}
showTriangle(context, board)
}

function paintStonesCounting(context, board, countingGroup) {
Expand Down
Loading