Skip to content

Commit

Permalink
refactor: gameType router push #190
Browse files Browse the repository at this point in the history
  • Loading branch information
habdevs committed Sep 11, 2023
1 parent 022ef5f commit e796f09
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions pages/games/[gameType].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const Game: NextPage<IGamePageProps> = ({ gameType, version }) => {
try {
const moves: [ISignedGameMove, ISignedGameMove] = playerIngameId === 0 ? [lastOpponentMoveSignedByAll, nextGameState.lastMove] : [nextGameState.lastMove, lastOpponentMoveSignedByAll];
const finishedGameResult = await finishGame(await getArbiter(), moves);
console.log('GAMETYPE ЛОГ finishedGameResult', finishedGameResult)

await sendMessage({
gameId: gameId,
Expand All @@ -157,8 +158,7 @@ const Game: NextPage<IGamePageProps> = ({ gameType, version }) => {
gameType,
});
// TODO: check update context @habdevs #190 add router.push
router.push('/game-result');
console.log('Записываем данные в контекст');
// router.push('/game-result');
const newFinishResult = {
winner: finishGameCheckResult?.winner || false,
isDraw: finishGameCheckResult?.isDraw || false,
Expand All @@ -167,34 +167,36 @@ const Game: NextPage<IGamePageProps> = ({ gameType, version }) => {

console.log('Попытка записи данных в контекст:', newFinishResult);
setFinishResult(newFinishResult);
// setFinishGameCheckResult(null);
setFinishGameCheckResult(null);
setFinishedGameState(finishedGameResult);
console.log('Завершение выполнения runFinishGameHandler', finishedGameResult);
console.log('finish gametype запись 1', newFinishResult);
} catch (error: any) {
if (error.reason.includes('invalid game move')) {
setFinishGameCheckResult({ winner: false, isDraw: false, cheatWin: true });
router.push('/game-result');
// router.push('/game-result');
const newFinishResult = {
winner: false,
isDraw: false,
cheatWin: true,
winner: finishGameCheckResult?.winner || false,
isDraw: finishGameCheckResult?.isDraw || false,
cheatWin: finishGameCheckResult?.cheatWin || true,
};
setFinishResult(newFinishResult);
console.log('finish gametype запись 2', newFinishResult);
}
if (error.reason.includes('moves are not in sequence')) {
console.log('moves are not in sequence');
router.push('/game-result');
// router.push('/game-result');
const newFinishResult = {
winner: false,
isDraw: false,
cheatWin: true,
winner: finishGameCheckResult?.winner || false,
isDraw: finishGameCheckResult?.isDraw || false,
cheatWin: finishGameCheckResult?.cheatWin || true,
};
setFinishResult(newFinishResult);
console.log('finish gametype запись 3', newFinishResult);
}
}
// TODO habdevs@ #190 route gameresult Page
router.push('/game-result');
};

const initTimeoutHandler = async () => {
Expand Down

0 comments on commit e796f09

Please sign in to comment.