public games have random map

This commit is contained in:
Evan
2025-02-09 12:29:13 -08:00
parent 74f523a770
commit 6ff4e10a7e
+7 -4
View File
@@ -5,12 +5,15 @@ import { Client } from "./Client";
import { GamePhase, GameServer } from "./GameServer";
import { Difficulty, GameMapType, GameType } from "../core/game/Game";
import { generateID } from "../core/Util";
import { PseudoRandom } from "../core/PseudoRandom";
export class GameManager {
private lastNewLobby: number = 0;
private games: GameServer[] = [];
private random = new PseudoRandom(123);
constructor(private config: ServerConfig) {}
public game(id: GameID): GameServer | null {
@@ -46,7 +49,7 @@ export class GameManager {
gameMap: GameMapType.World,
gameType: GameType.Private,
difficulty: Difficulty.Medium,
}),
})
);
return id;
}
@@ -54,7 +57,7 @@ export class GameManager {
hasActiveGame(gameID: GameID): boolean {
const game = this.games
.filter(
(g) => g.phase() == GamePhase.Lobby || g.phase() == GamePhase.Active,
(g) => g.phase() == GamePhase.Lobby || g.phase() == GamePhase.Active
)
.find((g) => g.id == gameID);
return game != null;
@@ -81,10 +84,10 @@ export class GameManager {
this.lastNewLobby = now;
lobbies.push(
new GameServer(generateID(), now, true, this.config, {
gameMap: GameMapType.World,
gameMap: this.random.randElement(Object.values(GameMapType)),
gameType: GameType.Public,
difficulty: Difficulty.Medium,
}),
})
);
}