Initial commit

This commit is contained in:
kascheml 2022-12-04 16:53:33 +01:00
commit 53be595352
9 changed files with 1134 additions and 0 deletions

35
src/index.ts Normal file
View file

@ -0,0 +1,35 @@
let max = Object.getOwnPropertyNames(Game.creeps)
.map(name => /([0-9]+)[^0-9]*$/.exec(name))
.filter(match => match !== null)
.map(match => parseInt((match as RegExpMatchArray)[1]))
.sort()
.pop() ?? 0;
const directions = [
TOP,
TOP_LEFT,
TOP_RIGHT,
LEFT,
RIGHT,
BOTTOM,
BOTTOM_LEFT,
BOTTOM_RIGHT,
];
export function loop() {
for (const spawnName in Game.spawns) {
if (Game.spawns[spawnName].spawning !== null) {
continue;
}
if (Game.spawns[spawnName].spawnCreep([MOVE], `Creep${max + 1}`) === OK) {
++max;
console.log(`Creep${max} has been spawned`)
}
}
for (const creepName in Game.creeps) {
Game.creeps[creepName].move(directions[Math.floor(Math.random() * directions.length)]);
Game.creeps[creepName].say(`Me ${creepName}`);
}
}