play again
This commit is contained in:
parent
08f04e09d4
commit
6aeca0838d
|
|
@ -1,13 +1,21 @@
|
||||||
// DO NOT MODIFY!
|
// DO NOT MODIFY!
|
||||||
// This file is generated by pyre.
|
// This file is generated by pyre.
|
||||||
// Generated: 2026-01-20 12:25:24.
|
// Generated: 2026-01-24 09:09:49.
|
||||||
|
|
||||||
import { send } from 'pyre/client'
|
import { send } from 'pyre/client'
|
||||||
|
|
||||||
|
export const playAgain = () => {
|
||||||
|
send({
|
||||||
|
type: 'action',
|
||||||
|
action: 'playAgain',
|
||||||
|
args: []
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const nameChange = (name: string) => {
|
export const nameChange = (name: string) => {
|
||||||
send({
|
send({
|
||||||
type: 'action',
|
type: 'action',
|
||||||
action: 'name:change',
|
action: 'nameChange',
|
||||||
args: [name]
|
args: [name]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { define, createThemes } from 'forge'
|
import { define, createThemes } from 'forge'
|
||||||
import { move, nameChange } from './actions'
|
import { move, nameChange, playAgain } from './actions'
|
||||||
import type { Game } from '../types'
|
import type { Game } from '../types'
|
||||||
import { sessionId } from 'pyre/client'
|
import { sessionId } from 'pyre/client'
|
||||||
|
|
||||||
|
|
@ -271,6 +271,7 @@ const WinBanner = define('WinBanner', {
|
||||||
<Root>
|
<Root>
|
||||||
<Title>{props.title}</Title>
|
<Title>{props.title}</Title>
|
||||||
<Button onClick={() => window.location.href = '/'}>New Game</Button>
|
<Button onClick={() => window.location.href = '/'}>New Game</Button>
|
||||||
|
<Button onClick={playAgain}>Play Again</Button>
|
||||||
</Root>
|
</Root>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ export { default } from 'pyre/server'
|
||||||
|
|
||||||
import type { Game, WinLine, xo } from './types'
|
import type { Game, WinLine, xo } from './types'
|
||||||
|
|
||||||
const game: Game = {
|
const newGame: Game = {
|
||||||
phase: 'play',
|
phase: 'play',
|
||||||
turn: 'x',
|
turn: 'x',
|
||||||
players: {},
|
players: {},
|
||||||
|
|
@ -15,7 +15,7 @@ const game: Game = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
const action = setup(game, {
|
const action = setup(newGame, {
|
||||||
onJoin(game, session) {
|
onJoin(game, session) {
|
||||||
if (game.players[session]) return
|
if (game.players[session]) return
|
||||||
|
|
||||||
|
|
@ -31,7 +31,20 @@ const action = setup(game, {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
action('name:change', (ctx, name: string) => {
|
action('playAgain', (ctx) => {
|
||||||
|
const game = ctx.game as Game
|
||||||
|
game.phase = 'play'
|
||||||
|
game.turn = 'x'
|
||||||
|
delete game.winLine
|
||||||
|
game.board = [
|
||||||
|
['', '', ''],
|
||||||
|
['', '', ''],
|
||||||
|
['', '', ''],
|
||||||
|
]
|
||||||
|
return game
|
||||||
|
})
|
||||||
|
|
||||||
|
action('nameChange', (ctx, name: string) => {
|
||||||
const game = ctx.game as Game
|
const game = ctx.game as Game
|
||||||
const player = game.players[ctx.session]
|
const player = game.players[ctx.session]
|
||||||
|
|
||||||
|
|
@ -52,6 +65,9 @@ action('move', (ctx, x: number, y: number) => {
|
||||||
if (game.board[x] === undefined || game.board[x][y] === undefined)
|
if (game.board[x] === undefined || game.board[x][y] === undefined)
|
||||||
throw new Error(`x,y not in board: ${x},${y}`)
|
throw new Error(`x,y not in board: ${x},${y}`)
|
||||||
|
|
||||||
|
if (game.board[x][y] !== '')
|
||||||
|
throw new Error(`someone already played at ${x},${y}`)
|
||||||
|
|
||||||
if (game.turn !== player)
|
if (game.turn !== player)
|
||||||
throw new Error('not your turn!')
|
throw new Error('not your turn!')
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user