Integrate SignalR for game session management and clean up unused local game logic.

This commit is contained in:
2026-02-22 20:52:00 +01:00
committed by Jonas
parent 306dacc300
commit 120c671dce
5 changed files with 205 additions and 19 deletions
@@ -3,27 +3,9 @@ import type { FieldSize } from '@/scripts/interfaces/FieldSize.ts'
class LocalGame {
public field: number[][]
private currentPlayer: number = 1;
constructor(fieldSize: FieldSize) {
this.field = Array.from({ length: fieldSize.y }, () => Array(fieldSize.x).fill(0))
}
place(locationX: number | null): void {
if(locationX === null) return;
console.log(
`Player ${this.currentPlayer} placed a field at x: ${locationX}`
)
for (let y = this.field.length - 1; y >= 0; y--) {
const row = this.field[y]
if (row && row[locationX] === 0) {
row[locationX] = this.currentPlayer
this.currentPlayer = this.currentPlayer === 1 ? 2 : 1
break
}
}
}
}
export default LocalGame
@@ -0,0 +1,13 @@
import * as signalR from '@microsoft/signalr';
class GameConnection{
public connection: signalR.HubConnection
constructor(gameSession: string) {
this.connection = new signalR.HubConnectionBuilder()
.withUrl(`/gameHub?gameSession=${gameSession}`)
.withAutomaticReconnect()
.build();
}
}
export default GameConnection;