You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
751 B

let max = Object.getOwnPropertyNames(Game.creeps)
.map(name => /([0-9]+)[^0-9]*$/.exec(name))
.filter(match => match !== null)
.map(match => parseInt(match))
.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}`);
}
}