63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
class Continent {
|
|
constructor(name) {
|
|
this.name = name;
|
|
this.yield = 0;
|
|
}
|
|
}
|
|
|
|
const REGIONS = {};
|
|
|
|
class Region {
|
|
constructor(name, continent) {
|
|
this.name = name;
|
|
this.owner = null;
|
|
this.strength = 0;
|
|
this.neighbours = new Set();
|
|
this.continent = continent;
|
|
|
|
REGIONS[name] = this;
|
|
}
|
|
|
|
static setNeighbours(region1, region2) {
|
|
region1.neighbours.add(region2);
|
|
region2.neighbours.add(region1);
|
|
}
|
|
|
|
static getRegion(name) {
|
|
return REGIONS[name];
|
|
}
|
|
|
|
/**
|
|
* Test if all regions are claimed or not.
|
|
*
|
|
* @returns {boolean}
|
|
*/
|
|
static allClaimed() {
|
|
return Object.values(REGIONS).find((r) => r.owner === null) === null;
|
|
}
|
|
|
|
claim(player) {
|
|
this.owner = player;
|
|
this.strength = 1;
|
|
}
|
|
|
|
reinforce(amount) {
|
|
this.strength += amount;
|
|
}
|
|
}
|
|
|
|
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);
|
|
const J = new Region("J", EAST);
|
|
|
|
const F = new Region("F", WEST);
|
|
const G = new Region("G", WEST);
|
|
const H = new Region("H", WEST);
|
|
const I = new Region("I", WEST);
|
|
const E = new Region("E", WEST);
|