import * as obfuscater from "./obfuscator.mjs"; import * as generator from "./generator.mjs" import * as marker from "./marker.mjs" import * as log from "../log.mjs" import * as flagger from "./flagger.mjs" import * as placer from "./placer.mjs" export class World { constructor(dimensions = [32,32], mines = 30) { this.mines = 200 this.dimensions = dimensions; this.isGenerated = false; this.isObfuscated = false; this.isMarked = false; this.data = Array.from(Array(this.dimensions[0]), () => new Array(this.dimensions[1])); for (let x = 0; x < this.dimensions[0]; x++){ for (let y = 0; y < this.dimensions[1]; y++){ this.data[x][y] = {type: 1, flag: 0, mask: true} } } } click (location, mode, player) { if (this.isGenerated) { if (mode === 2) { this.data = flagger.flag(this.data, location, player) } if (mode === 0) { this.data = placer.place(this.data, location, player) } } else { this.generate(location).mark(); this.data = placer.place(this.data, location, player) } } generate(location) { if (this.isGenerated) return log.log("Already Generated"); return generator.generate(this, location); } mark() { if (this.isMarked) return log.log("Already Marked!"); return marker.mark(this); } obfuscate() { if (this.isObfuscated) return log.log("already done") const tempWorld = JSON.parse(JSON.stringify(this));; return obfuscater.obfuscate(tempWorld); } }