diff --git a/src/index.ts b/src/index.ts
index 0f02d2d..787e214 100755
--- a/src/index.ts
+++ b/src/index.ts
@@ -4,6 +4,7 @@ import { staticPlugin } from '@elysiajs/static';
import { cookie } from '@elysiajs/cookie';
import { WebSocketHandler } from './web-socket-handler';
import { ElysiaWS } from 'elysia/dist/ws';
+import { createStoneSvg } from './view/board-renderer';
const wsHandler = new WebSocketHandler();
export type WS = ElysiaWS<{ query: { playerId: string; gameId: string } }>;
@@ -90,6 +91,20 @@ const app = new Elysia()
headers: { 'Content-Type': 'text/html' },
status: 200,
});
+ })
+ .get('/black-stone.svg', () => {
+ const stoneSvg = createStoneSvg('black', false);
+ return new Response(String(stoneSvg), {
+ headers: { 'Content-Type': 'image/svg+xml' },
+ status: 200,
+ });
+ })
+ .get('/white-stone.svg', () => {
+ const stoneSvg = createStoneSvg('white', false);
+ return new Response(String(stoneSvg), {
+ headers: { 'Content-Type': 'image/svg+xml' },
+ status: 200,
+ });
});
const port = Number(process.env.PORT || 3000);
diff --git a/src/view/board-renderer.tsx b/src/view/board-renderer.tsx
index d48b90c..3c2d2b2 100755
--- a/src/view/board-renderer.tsx
+++ b/src/view/board-renderer.tsx
@@ -3,6 +3,34 @@ import { GomokuGame } from '../game/game-instance';
import { PlayerConnection } from '../player-connection';
import { GameServer } from '../game-server';
+export function createStoneSvg(
+ color: 'black' | 'white',
+ isHighlighted: boolean = false,
+): JSX.Element {
+ const colorClass =
+ color === 'black' ? 'stone-black-heart' : 'stone-white-heart';
+ const lastMoveClass = isHighlighted ? 'last-move' : '';
+
+ return (
+
+ );
+}
+
export function broadcastBoard(server: GameServer) {
server.connections.forEach((conn: PlayerConnection) =>
broadcastBoardToPlayer(server, conn),
@@ -34,28 +62,8 @@ function renderGameBoardHtml(
const intersectionId = `intersection-${row}-${col}`;
let stoneHtml: JSX.Element | null;
if (stone) {
- const colorClass =
- stone === 'black' ? 'stone-black-heart' : 'stone-white-heart';
- const lastMoveClass =
- col == lastMove.col && row == lastMove.row ? 'last-move' : '';
- stoneHtml = (
-
- );
+ const isLastMove = col == lastMove.col && row == lastMove.row;
+ stoneHtml = createStoneSvg(stone, isLastMove);
} else {
stoneHtml = null;
}