better random, improved map

This commit is contained in:
evanpelle
2024-09-05 19:19:52 -07:00
parent 79aa06aed5
commit 4161b4d71c
6 changed files with 15 additions and 9 deletions
+1 -1
View File
@@ -94,9 +94,9 @@
* send boat even if touching DONE 9/4/2024
* when attacking by boat, attack execution only starts from boat pixel DONE 9/4/2024
* Make three terrain types: Plains, highlands, mountains DONE 9/5/2024
* directed expansion
* more random names for game id & client id
* Make fake humans
* directed expansion
* UI: win condition & popup
* UI: boats
* UI: current attacks
File diff suppressed because one or more lines are too long
Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 KiB

After

Width:  |  Height:  |  Size: 823 KiB

+4 -6
View File
@@ -1,7 +1,4 @@
import {getConfig} from "../core/configuration/Config";
import {defaultConfig} from "../core/configuration/DefaultConfig";
import {devConfig} from "../core/configuration/DevConfig";
import {PseudoRandom} from "../core/PseudoRandom";
import {GameID, Lobby, ServerMessage, ServerMessageSchema} from "../core/Schemas";
import {loadTerrainMap, TerrainMap} from "../core/TerrainMapLoader";
import {ClientGame, createClientGame} from "./ClientGame";
@@ -9,6 +6,7 @@ import backgroundImage from '../../resources/images/TerrainMapFrontPage.png';
import favicon from '../../resources/images/Favicon.png';
import './styles.css';
import {generateUniqueId} from "../core/Util";
class Client {
@@ -69,7 +67,7 @@ class Client {
lobbyButton.classList.toggle('highlighted', this.isLobbyHighlighted);
}
if (nameElement) nameElement.textContent = `Game ${lobby.id}`;
if (nameElement) nameElement.textContent = `Game ${lobby.id.substring(0, 3)}`;
if (timerElement) {
const timeRemaining = Math.max(0, Math.floor((lobby.msUntilStart) / 1000));
timerElement.textContent = `Starts in: ${timeRemaining}s`;
@@ -79,7 +77,7 @@ class Client {
if (lobbies.length > 1) {
const nextLobby = lobbies[1]
const nextGame = document.getElementById('next-game');
nextGame.textContent = `Next Game: ${nextLobby.id}`
nextGame.textContent = `Next Game: ${nextLobby.id.substring(0, 3)}`
}
}
@@ -122,7 +120,7 @@ class Client {
console.log(`got ip ${clientIP}`)
this.game = createClientGame(
getUsername(),
new PseudoRandom(Date.now()).nextID(), // TODO this can cause dup ids
generateUniqueId(),
clientIP,
lobby.id,
getConfig(),
+7
View File
@@ -97,4 +97,11 @@ export function getMode(list: string[]): string {
}
return mode;
}
export function generateUniqueId(): string {
if (typeof crypto === 'undefined' || !crypto.randomUUID) {
throw new Error('crypto.randomUUID is not supported in this environment');
}
return crypto.randomUUID();
}
+2 -1
View File
@@ -4,6 +4,7 @@ import {PseudoRandom} from "../core/PseudoRandom";
import WebSocket from 'ws';
import {ClientID, GameID} from "../core/Schemas";
import {Client} from "./Client";
import {generateUniqueId} from "../core/Util";
export class GameManager {
@@ -37,7 +38,7 @@ export class GameManager {
const now = Date.now()
if (now > this.lastNewLobby + this.config.gameCreationRate()) {
this.lastNewLobby = now
const id = this.random.nextID()
const id = generateUniqueId()
lobbies.push(new GameServer(id, now, this.config))
}