@@ -247,7 +247,7 @@ const boardGridRef = ref<HTMLElement | null>(null)
247247const lastMove = ref <{ from: { row: number ; col: number }; to: { row: number ; col: number } } | null >(null )
248248const positionHistory = ref <string []>([getPositionKey (board .value , currentTurn .value , lastMove .value )])
249249const halfmoveClock = ref <number >(0 )
250- const INITIAL_CLOCK_SECONDS = null
250+ const INITIAL_CLOCK_SECONDS: number | null = null
251251const clockIncrementSeconds = ref (0 )
252252const whiteTimeSeconds = ref <number | null >(INITIAL_CLOCK_SECONDS )
253253const blackTimeSeconds = ref <number | null >(INITIAL_CLOCK_SECONDS )
@@ -306,8 +306,8 @@ const boardHistory = ref<Array<{
306306 currentTurn: Color
307307 lastMove: { from: { row: number ; col: number }; to: { row: number ; col: number } } | null
308308 halfmoveClock: number
309- whiteTimeSeconds: number
310- blackTimeSeconds: number
309+ whiteTimeSeconds: number | null
310+ blackTimeSeconds: number | null
311311 hasGameStarted: boolean
312312 clockStarted: boolean
313313 activeClockColor: Color | null
@@ -526,8 +526,8 @@ const handleClockTimeout = (expiredColor: Color) => {
526526}
527527
528528const startClock = (color : Color ) => {
529- // 如果设定限时为 0,则不启用棋钟
530- if (whiteTimeSeconds .value === 0 || isGameOver .value ) {
529+ // 如果设定限时为 0 或未设置限时 ,则不启用棋钟
530+ if (whiteTimeSeconds .value === null || whiteTimeSeconds . value === 0 || isGameOver .value ) {
531531 stopClock ()
532532 return
533533 }
@@ -543,14 +543,18 @@ const startClock = (color: Color) => {
543543 }
544544
545545 if (activeClockColor .value === ' white' ) {
546- whiteTimeSeconds .value = Math .max (0 , whiteTimeSeconds .value - 1 )
547- if (whiteTimeSeconds .value === 0 ) {
548- handleClockTimeout (' white' )
546+ if (whiteTimeSeconds .value !== null ) {
547+ whiteTimeSeconds .value = Math .max (0 , whiteTimeSeconds .value - 1 )
548+ if (whiteTimeSeconds .value === 0 ) {
549+ handleClockTimeout (' white' )
550+ }
549551 }
550552 } else {
551- blackTimeSeconds .value = Math .max (0 , blackTimeSeconds .value - 1 )
552- if (blackTimeSeconds .value === 0 ) {
553- handleClockTimeout (' black' )
553+ if (blackTimeSeconds .value !== null ) {
554+ blackTimeSeconds .value = Math .max (0 , blackTimeSeconds .value - 1 )
555+ if (blackTimeSeconds .value === 0 ) {
556+ handleClockTimeout (' black' )
557+ }
554558 }
555559 }
556560 }, 1000 )
@@ -573,9 +577,13 @@ const applyClockAfterMove = (moverColor: Color, nextTurn: Color, nextBoard: Boar
573577
574578 if (hasGameStarted .value ) {
575579 if (moverColor === ' white' ) {
576- whiteTimeSeconds .value += clockIncrementSeconds .value
580+ if (whiteTimeSeconds .value !== null ) {
581+ whiteTimeSeconds .value += clockIncrementSeconds .value
582+ }
577583 } else {
578- blackTimeSeconds .value += clockIncrementSeconds .value
584+ if (blackTimeSeconds .value !== null ) {
585+ blackTimeSeconds .value += clockIncrementSeconds .value
586+ }
579587 }
580588 startClock (nextTurn )
581589 }
0 commit comments