2023-03-05 17:19:37 +00:00
|
|
|
const REGIONS = {};
|
2023-03-03 17:34:15 +00:00
|
|
|
|
2023-02-06 11:04:37 +00:00
|
|
|
class Continent {
|
|
|
|
constructor(name) {
|
|
|
|
this.name = name;
|
|
|
|
this.yield = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-13 14:52:14 +00:00
|
|
|
class Strength {
|
2023-03-17 10:42:11 +00:00
|
|
|
constructor(cipherText) {
|
|
|
|
this.cipherText = cipherText;
|
2023-03-13 14:52:14 +00:00
|
|
|
this.assumedStrength = null;
|
|
|
|
}
|
|
|
|
|
2023-03-17 10:42:11 +00:00
|
|
|
update(cipherText) {
|
|
|
|
if (this.cipherText === null) {
|
|
|
|
this.cipherText = cipherText;
|
2023-03-13 14:52:14 +00:00
|
|
|
} else {
|
2023-03-17 10:42:11 +00:00
|
|
|
this.cipherText.update(cipherText);
|
2023-03-13 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.assumedStrength = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 17:34:15 +00:00
|
|
|
export class Region {
|
2023-02-06 11:04:37 +00:00
|
|
|
constructor(name, continent) {
|
|
|
|
this.name = name;
|
|
|
|
this.owner = null;
|
2023-03-13 14:52:14 +00:00
|
|
|
this.strength = new Strength(null);
|
2023-02-06 11:04:37 +00:00
|
|
|
this.neighbours = new Set();
|
|
|
|
this.continent = continent;
|
|
|
|
|
|
|
|
REGIONS[name] = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
static setNeighbours(region1, region2) {
|
|
|
|
region1.neighbours.add(region2);
|
|
|
|
region2.neighbours.add(region1);
|
|
|
|
}
|
|
|
|
|
2023-03-03 17:34:15 +00:00
|
|
|
static allRegionsClaimed() {
|
|
|
|
return (
|
|
|
|
Object.values(REGIONS).find((region) => region.owner === null) === undefined
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-06 11:04:37 +00:00
|
|
|
static getRegion(name) {
|
|
|
|
return REGIONS[name];
|
|
|
|
}
|
|
|
|
|
2023-03-03 17:34:15 +00:00
|
|
|
static getAllRegions() {
|
|
|
|
return Object.values(REGIONS);
|
|
|
|
}
|
|
|
|
|
2023-03-17 10:42:11 +00:00
|
|
|
claim(player, cipherText) {
|
2023-02-06 11:04:37 +00:00
|
|
|
this.owner = player;
|
2023-03-17 10:42:11 +00:00
|
|
|
this.strength.update(cipherText);
|
2023-03-13 14:52:14 +00:00
|
|
|
this.strength.assumedStrength = 1;
|
2023-02-06 11:04:37 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 10:42:11 +00:00
|
|
|
reinforce(cipherText) {
|
|
|
|
this.strength.update(cipherText);
|
2023-03-13 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isClaimed() {
|
2023-03-17 10:42:11 +00:00
|
|
|
return this.strength.cipherText !== null;
|
2023-03-13 14:52:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
displayStrength() {
|
|
|
|
if (this.owner === null) {
|
|
|
|
return "";
|
2023-03-17 10:42:11 +00:00
|
|
|
} else if (!this.strength.cipherText.readOnly) {
|
|
|
|
return this.strength.cipherText.plainText;
|
2023-03-13 14:52:14 +00:00
|
|
|
} else if (this.strength.assumedStrength !== null) {
|
|
|
|
return `${this.strength.assumedStrength}`;
|
|
|
|
} else {
|
|
|
|
return "?";
|
|
|
|
}
|
2023-02-06 11:04:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-06 12:30:24 +00:00
|
|
|
const EAST = new Continent("East");
|
|
|
|
const WEST = new Continent("West");
|
|
|
|
|
|
|
|
const A = new Region("A", EAST);
|
|
|
|
const B = new Region("B", EAST);
|
|
|
|
const C = new Region("C", EAST);
|
|
|
|
const D = new Region("D", EAST);
|
2023-02-06 13:03:25 +00:00
|
|
|
const J = new Region("J", EAST);
|
2023-02-06 12:30:24 +00:00
|
|
|
|
|
|
|
const F = new Region("F", WEST);
|
|
|
|
const G = new Region("G", WEST);
|
|
|
|
const H = new Region("H", WEST);
|
|
|
|
const I = new Region("I", WEST);
|
2023-02-06 13:03:25 +00:00
|
|
|
const E = new Region("E", WEST);
|
2023-02-08 17:55:45 +00:00
|
|
|
|
2023-02-15 18:00:25 +00:00
|
|
|
Region.setNeighbours(A, B);
|
|
|
|
Region.setNeighbours(A, C);
|
|
|
|
Region.setNeighbours(B, C);
|
|
|
|
Region.setNeighbours(B, J);
|
|
|
|
Region.setNeighbours(C, D);
|
|
|
|
Region.setNeighbours(C, F);
|
|
|
|
Region.setNeighbours(E, J);
|
|
|
|
Region.setNeighbours(E, I);
|
|
|
|
Region.setNeighbours(E, H);
|
|
|
|
Region.setNeighbours(F, J);
|
|
|
|
Region.setNeighbours(F, G);
|
|
|
|
Region.setNeighbours(G, H);
|
|
|
|
Region.setNeighbours(G, I);
|
|
|
|
Region.setNeighbours(H, I);
|