create basic win popup

This commit is contained in:
evanpelle
2024-09-16 11:51:24 -07:00
parent 2f626bcc39
commit 534d97abb3
15 changed files with 287 additions and 27 deletions
+47
View File
@@ -0,0 +1,47 @@
import {EventBus, GameEvent} from "../EventBus"
import {Execution, MutableGame, MutablePlayer, Player, PlayerID} from "../Game"
export class WinEvent implements GameEvent {
constructor(public readonly winner: Player) { }
}
export class WinCheckExecution implements Execution {
private active = true
private mg: MutableGame
constructor(private eventBus: EventBus) {
}
init(mg: MutableGame, ticks: number) {
this.mg = mg
}
tick(ticks: number) {
if (ticks % 10 != 0) {
return
}
const sorted = this.mg.players().sort((a, b) => b.numTilesOwned() - a.numTilesOwned())
if (sorted.length == 0) {
return
}
const max = sorted[0]
if (max.numTilesOwned() / this.mg.numLandTiles() * 100 > this.mg.config().percentageTilesOwnedToWin()) {
this.eventBus.emit(new WinEvent(max))
this.active = false
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}