2022-06-24 13:37:03 +00:00
|
|
|
import * as obfuscater from "./obfuscator.js";
|
|
|
|
import * as generator from "./generator.js";
|
|
|
|
import * as marker from "./marker.js";
|
|
|
|
import * as flagger from "./flagger.js";
|
|
|
|
import * as placer from "./placer.js";
|
|
|
|
export class World {
|
|
|
|
constructor(options) {
|
|
|
|
this.mines = options.mines;
|
|
|
|
this.width = options.width * 1;
|
|
|
|
this.height = options.height * 1;
|
|
|
|
this.isGenerated = false;
|
|
|
|
this.isObfuscated = false;
|
|
|
|
this.isMarked = false;
|
|
|
|
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++) {
|
|
|
|
this.data[x][y] = { type: 1, flag: 0, mask: true };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
click(x, y, mode, player) {
|
|
|
|
if (this.isGenerated) {
|
|
|
|
if (mode === 2) {
|
|
|
|
this.data = flagger.flag(x, y, this.data, player);
|
|
|
|
}
|
|
|
|
if (mode === 0) {
|
2022-06-24 14:34:25 +00:00
|
|
|
this.data = placer.place(x, y, this.data);
|
2022-06-24 13:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.generate(x, y).mark();
|
2022-06-24 14:34:25 +00:00
|
|
|
this.data = placer.place(x, y, this.data);
|
2022-06-24 13:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
generate(x, y) {
|
|
|
|
if (this.isGenerated)
|
2022-06-24 14:34:25 +00:00
|
|
|
return console.log("Already Generated");
|
2022-06-24 13:37:03 +00:00
|
|
|
return generator.generate(x, y, this);
|
|
|
|
}
|
|
|
|
mark() {
|
|
|
|
if (this.isMarked)
|
2022-06-24 14:34:25 +00:00
|
|
|
return console.log("Already Marked!");
|
2022-06-24 13:37:03 +00:00
|
|
|
return marker.mark(this);
|
|
|
|
}
|
|
|
|
obfuscate() {
|
|
|
|
if (this.isObfuscated)
|
2022-06-24 14:34:25 +00:00
|
|
|
return console.log("already done");
|
2022-06-24 13:37:03 +00:00
|
|
|
const tempWorld = JSON.parse(JSON.stringify(this));
|
|
|
|
;
|
|
|
|
return obfuscater.obfuscate(tempWorld);
|
|
|
|
}
|
|
|
|
}
|