MultiplayerMinesweeper/scripts/game.mjs
Alexander Bass fe794b69a9 Before starting work on only sending changes in world
Doing this to allow for stupidly big worlds (also better network usage)
2022-06-24 08:10:06 -04:00

44 lines
1,015 B
JavaScript

import {Player} from "./player.mjs"
import * as log from "./log.mjs"
import {roomManager} from "./roomManager.mjs"
import { World} from "./world/world.mjs"
export class Game {
constructor(id, options) {
this.id = id;
this.players = [];
this.oldWorld = []
this.world = new World(options)
}
addPlayer(id, name, color) {
if (this.getAllNames().includes(name)) return false
const player = new Player(id, name, color);
this.players.push(player);
return player
}
removePlayerByID(id) {
this.players = this.players.filter(obj => obj.id != id);
log.log("removed player - " + id)
if (this.players.length < 1) {
roomManager.removeGameByID(this.id);
}
}
getAllIDs() {
let ids = []
for (let i = 0; i < this.players.length; i++) {
ids.push(this.players[i].id)
}
return ids
}
getAllNames() {
let names = []
for (let i = 0; i < this.players.length; i++) {
names.push(this.players[i].name)
}
return names
}
}