Improve title box with turn indicator
This commit is contained in:
parent
7cbeef6482
commit
6bb62b9c87
4 changed files with 78 additions and 28 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue