Improve title box with turn indicator

This commit is contained in:
sepia 2025-07-20 19:50:33 -05:00
parent 7cbeef6482
commit 6bb62b9c87
4 changed files with 78 additions and 28 deletions

View file

@ -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 = '<div id="game-board" class="game-board-grid">';
const currentPlayerColor =
Object.entries(gameState.players).find(([_, id]) => id === playerId)?.[0] ||
Object.entries(game.players).find(([_, id]) => id === playerId)?.[0] ||
null;
const isPlayersTurn =
gameState.status === 'playing' &&
gameState.currentPlayer === currentPlayerColor;
game.status === 'playing' && game.currentPlayerColor === currentPlayerColor;
for (let row = 0; row < gameState.board.length; row++) {
for (let col = 0; col < gameState.board[row].length; col++) {
const stone = gameState.board[row][col];
for (let row = 0; row < game.board.length; row++) {
for (let col = 0; col < game.board[row].length; col++) {
const stone = game.board[row][col];
const intersectionId = `intersection-${row}-${col}`;
let stoneHtml = '';
if (stone) {