Skip to content

Commit 1dadc6b

Browse files
committed
detect timeout
1 parent 5dcf9aa commit 1dadc6b

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/main/client/src/feature/game/Game.jsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
StompContext,
2323
tfetch,
2424
doTry,
25-
COLORS,
2625
} from "src/util.js"
2726
import {
2827
PointList,
@@ -61,7 +60,6 @@ import {
6160
isReviewing,
6261
isCounting,
6362
teleport,
64-
setWinnerByTime,
6563
} from "./state.js"
6664
import {
6765
BoardSettings,
@@ -126,13 +124,16 @@ function Board({gameState, setGameState}) {
126124
setTimeout(t)
127125
if (t <= 0) {
128126
clearInterval(intervalIdRef.current)
129-
let gameState = gameStateRef.current
130-
let updated = setWinnerByTime(gameState, currentColor(gameState) ^ COLORS)
131-
setGameState(updated)
127+
window.setTimeout(() => {
128+
stompClient.publish({
129+
destination: "/app/game/move",
130+
body: JSON.stringify({ x: -1, y: -1 }),
131+
})
132+
}, 100)
132133
}
133134
}, 1000)
134135

135-
}, [setTimeout, timesetting, setGameState])
136+
}, [setTimeout, timesetting, stompClient])
136137

137138
useEffect(() => {
138139
resetCountdown()
@@ -363,7 +364,7 @@ function Board({gameState, setGameState}) {
363364
paintMoveNumbers(context, board)
364365
} else if (!counting && !end) {
365366
paintLastMove(context, lastMove, timeoutRef.current)
366-
} else if (lastMove) {
367+
} else if (lastMove && !lastMove.action) {
367368
paintNumber(context, lastMove.x, lastMove.y, lastMove.n + 1, lastMove.color)
368369
}
369370
if (currentPlayer(gameState) !== auth.name) {

src/main/client/src/feature/game/state.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export function initialState() {
3636
baseBoard: [],
3737
historyBoard: [],
3838
viewPos: Number.NaN,
39-
winnerByTime: 0,
4039
dim: 0,
4140
timesetting: 0,
4241
handicap: 0,
@@ -102,13 +101,10 @@ export function countingAgreed({moves, myColor}) {
102101
return move.color === myColor && move.action === "agreeCounting"
103102
}
104103

105-
export function gameHasEnded({state, winnerByTime, moves}) {
104+
export function gameHasEnded({state, moves}) {
106105
if (state === STATE_TIMEOUT) {
107106
return true
108107
}
109-
if (winnerByTime) {
110-
return true
111-
}
112108
if (!moves.length) {
113109
return false
114110
}
@@ -224,12 +220,6 @@ export function addMove(baseState, move) {
224220
})
225221
}
226222

227-
export function setWinnerByTime(baseState, winnerByTime) {
228-
return produce(baseState, (draft) => {
229-
draft.winnerByTime = winnerByTime
230-
})
231-
}
232-
233223
export function createGameState(game, auth) {
234224
let baseBoard = Array(game.dim)
235225
let historyBoard = Array(game.dim)

0 commit comments

Comments
 (0)