Add bot play, replay creation, and move phrases
Create replay games when a match ends (win or draw) and include ReplayGameCode in the GameEnded payload; adjust deletion timing to keep the replay longer and clean up original games sooner. Update game deletion logic to only destroy non-running games and schedule immediate deletion for quick timeouts. Add optional local bot support (botPlayer2 flag) with automated random-delayed moves and a UI switch in the game creation menu; expose botPlayer2 in GameSettings and LocalMode defaults. Introduce RandomPlaceMessage utility to generate varied turn descriptions and integrate it into LocalGame and OnlineGame. Also include a minor whitespace fix in Game.cs.
This commit is contained in:
@@ -4,12 +4,14 @@ import GameConnection, {
|
||||
type GameInformationDto,
|
||||
type GameEnded,
|
||||
} from '../signalR/GameConnection';
|
||||
import { getRandomMovePhrase } from '@/scripts/utils/RandomPlaceMessage';
|
||||
|
||||
class LocalGame {
|
||||
public player1: GameConnection;
|
||||
public player2: GameConnection;
|
||||
public currentDescription: string = 'Warte auf Spielaufbau ...';
|
||||
private gameId: string = '';
|
||||
private botGame = false;
|
||||
|
||||
public gameState: GameInformationDto | undefined;
|
||||
public onGameStateChanged?: (gameState: GameInformationDto | undefined) => void;
|
||||
@@ -50,6 +52,8 @@ class LocalGame {
|
||||
await this.player1.connect(settings.playerName1);
|
||||
await this.player2.connect(settings.playerName2 ?? 'Spieler 2');
|
||||
|
||||
this.botGame = settings.botPlayer2 ?? false;
|
||||
|
||||
await this.player1.createGame(settings.fieldSize);
|
||||
}
|
||||
|
||||
@@ -63,7 +67,15 @@ class LocalGame {
|
||||
async drop(index: number) {
|
||||
if (this.gameState?.currentTurn == 1) {
|
||||
this.player1.drop(this.gameId, index);
|
||||
} else {
|
||||
|
||||
if (this.botGame) {
|
||||
const randomDelay = Math.random() * 2000 + 1000;
|
||||
setTimeout(() => {
|
||||
const botIndex = Math.floor(Math.random() * this.gameState!.currentField.length);
|
||||
this.player2.drop(this.gameId, botIndex);
|
||||
}, randomDelay);
|
||||
}
|
||||
} else if(!this.botGame) {
|
||||
this.player2.drop(this.gameId, index);
|
||||
}
|
||||
}
|
||||
@@ -71,10 +83,10 @@ class LocalGame {
|
||||
changePlaceDescription() {
|
||||
const playerName =
|
||||
this.gameState?.currentTurn == 1 ? this.player1.playerName : this.player2.playerName;
|
||||
this.currentDescription = `${playerName} ist dran mit setzen!`;
|
||||
this.currentDescription = getRandomMovePhrase(playerName);
|
||||
}
|
||||
|
||||
async disconnectAll(){
|
||||
async disconnectAll() {
|
||||
await this.player1.disconnect();
|
||||
await this.player2.disconnect();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user