2022-06-22 01:51:09 +00:00
|
|
|
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 {
|
2022-06-23 05:44:57 +00:00
|
|
|
constructor(options) {
|
|
|
|
this.mines = options.mines
|
|
|
|
this.width = options.width*1
|
|
|
|
this.height = options.height*1
|
2022-06-22 01:51:09 +00:00
|
|
|
this.isGenerated = false;
|
|
|
|
this.isObfuscated = false;
|
|
|
|
this.isMarked = false;
|
2022-06-23 05:44:57 +00:00
|
|
|
this.data = Array.from(Array(this.width), () => new Array(this.height));
|
|
|
|
for (let x = 0; x < this.width; x++){
|
|
|
|
for (let y = 0; y < this.height; y++){
|
2022-06-22 01:51:09 +00:00
|
|
|
this.data[x][y] = {type: 1, flag: 0, mask: true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
click (x, y, mode, player) {
|
2022-06-22 01:51:09 +00:00
|
|
|
if (this.isGenerated) {
|
|
|
|
if (mode === 2) {
|
2022-06-23 05:44:57 +00:00
|
|
|
this.data = flagger.flag(x, y, this.data, player)
|
2022-06-22 01:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mode === 0) {
|
2022-06-23 05:44:57 +00:00
|
|
|
this.data = placer.place(x, y, this.data, player)
|
2022-06-22 01:51:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-06-23 05:44:57 +00:00
|
|
|
this.generate(x, y).mark();
|
|
|
|
this.data = placer.place(x, y, this.data, player)
|
2022-06-22 01:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-23 05:44:57 +00:00
|
|
|
generate(x, y) {
|
2022-06-22 01:51:09 +00:00
|
|
|
if (this.isGenerated) return log.log("Already Generated");
|
2022-06-23 05:44:57 +00:00
|
|
|
return generator.generate(x, y, this);
|
2022-06-22 01:51:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|