Initial commit
This commit is contained in:
commit
53be595352
9 changed files with 1134 additions and 0 deletions
src
35
src/index.ts
Normal file
35
src/index.ts
Normal 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}`);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue