2022-06-22 01:51:09 +00:00
|
|
|
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(name) {
|
|
|
|
this.name = name;
|
|
|
|
this.players = [];
|
2022-06-23 00:16:57 +00:00
|
|
|
this.world = new World([16,9])
|
2022-06-22 01:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addPlayer(id, name) {
|
|
|
|
if (this.getAllNames().includes(name)) return false
|
|
|
|
var color = 1
|
|
|
|
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.removeGame(this.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
getSettings() {
|
|
|
|
const settings =
|
|
|
|
{
|
|
|
|
mines: this.world.mines,
|
|
|
|
dimensions: this.world.dimensions,
|
|
|
|
name: this.name
|
|
|
|
}
|
|
|
|
return settings
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|