Skip to content

Commit

Permalink
Add highlight last move
Browse files Browse the repository at this point in the history
  • Loading branch information
FPT-NMTung committed Dec 20, 2024
1 parent 313f047 commit bad2490
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pages/gamePage/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ export const drawTable = (cells) => {
CTX.stroke()
}

listCell.forEach(({x, y, side}) => {
renderCell(x, y, side, offsetX, offsetY)
listCell.forEach(({x, y, side}, index) => {
const isLastMove = index === listCell.length - 1
renderCell(x, y, side, offsetX, offsetY, isLastMove)
})
}

Expand Down Expand Up @@ -146,7 +147,7 @@ export const handleClickStep = (evt) => {
}
}

export const renderCell = (x, y, side, offsetX, offsetY) => {
export const renderCell = (x, y, side, offsetX, offsetY, isLastMove) => {
// calc location

CTX.beginPath();
Expand All @@ -163,4 +164,9 @@ export const renderCell = (x, y, side, offsetX, offsetY) => {
CTX.fillStyle = "gray";
}
CTX.fill();
if (isLastMove) {
CTX.lineWidth = 2;
CTX.strokeStyle = "red";
CTX.stroke();
}
}

0 comments on commit bad2490

Please sign in to comment.