diff --git a/public/style.css b/public/style.css index 8a5703d..f17216a 100644 --- a/public/style.css +++ b/public/style.css @@ -97,6 +97,7 @@ body { } #title-box { + font-size: 1.25em; padding-top: 0.25em; padding-bottom: 0.25em; } @@ -184,6 +185,29 @@ body { background-color: var(--color-on-primary); } +.player-name { + font-weight: bold; +} + +.player-name.player-black { + color: var(--color-primary-light); +} + +.player-name.player-white { + color: var(--color-on-primary); + text-shadow: + -1px -1px 0 var(--color-neutral-900), + 1px -1px 0 var(--color-neutral-900), + -1px 1px 0 var(--color-neutral-900), + 1px 1px 0 var(--color-neutral-900); +} + +.player-name.player-to-play { + border: 2px solid var(--color-focus-ring); + border-radius: 10px; + padding: 2px; +} + .last-move { box-shadow: 0 0 5px 3px var(--color-warning-light); } diff --git a/src/game/game-instance.ts b/src/game/game-instance.ts index d57aa0b..9000c38 100644 --- a/src/game/game-instance.ts +++ b/src/game/game-instance.ts @@ -7,7 +7,7 @@ type BoardCell = null | 'black' | 'white'; export class GameInstance { public readonly id: string; public readonly board: BoardCell[][]; - public currentPlayer: PlayerColor | null; + public currentPlayerColor: PlayerColor | null; public status: GameStatus; public winner: null | PlayerColor | 'draw'; public players: { black?: string; white?: string }; @@ -20,12 +20,20 @@ export class GameInstance { this.board = Array.from({ length: this.boardSize }, () => Array(this.boardSize).fill(null), ); - this.currentPlayer = null; + this.currentPlayerColor = null; this.status = 'waiting'; this.winner = null; this.players = {}; } + public getCurrentPlayerId(): string | undefined { + if (this.currentPlayerColor === 'black') { + return this.players.black; + } else { + return this.players.white; + } + } + public getPlayerCount(): number { return Object.values(this.players).filter(Boolean).length; } @@ -52,7 +60,7 @@ export class GameInstance { // If both players have joined, start the game. if (this.players.black && this.players.white) { - this.currentPlayer = 'black'; + this.currentPlayerColor = 'black'; this.status = 'playing'; } return true; @@ -77,7 +85,7 @@ export class GameInstance { } // Validate it's the player's turn - if (this.currentPlayer !== playerColor) { + if (this.currentPlayerColor !== playerColor) { return { success: false, error: 'Not your turn' }; } @@ -99,7 +107,7 @@ export class GameInstance { if (this.checkWin(row, col, playerColor)) { this.winner = playerColor; this.status = 'finished'; - this.currentPlayer = null; + this.currentPlayerColor = null; return { success: true }; } @@ -107,12 +115,12 @@ export class GameInstance { if (this.moveCount === this.boardSize * this.boardSize) { this.winner = 'draw'; this.status = 'finished'; - this.currentPlayer = null; + this.currentPlayerColor = null; return { success: true }; } // Switch turns - this.currentPlayer = playerColor === 'black' ? 'white' : 'black'; + this.currentPlayerColor = playerColor === 'black' ? 'white' : 'black'; return { success: true }; } diff --git a/src/view/board-renderer.ts b/src/view/board-renderer.ts index 51e5090..bf3ee81 100644 --- a/src/view/board-renderer.ts +++ b/src/view/board-renderer.ts @@ -1,26 +1,20 @@ import { GameInstance } from '../game/game-instance'; -export type GameStateType = Pick< - GameInstance, - 'id' | 'board' | 'currentPlayer' | 'status' | 'winner' | 'players' ->; - export function renderGameBoardHtml( - gameState: GameStateType, + game: GameInstance, playerId: string, ): string { let boardHtml = '