1.section1基本挖矿:
1.鼠标点击建立自己的基地
2.生成你的creepss采集能源虫
Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE],'Harvester1');
3.主函数
module.exports.loop = function () {//主程序入口
for(var name in Game.creeps) {//遍历所有工人,Game.creeps会返回所有游戏中的工人
var creep = Game.creeps[name];//得到当前的工人
if(creep.store.getFreeCapacity() > 0) {//检测工人有没有空余空间
var sources = creep.room.find(FIND_SOURCES);//如果有,那就找到附近的矿点
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {//如果工人够不到矿点
creep.moveTo(sources[0]);//移动到矿点的位置
}
}
else {
if(creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {/工人没有空余空间的时候,将能量转移到母巢spawn里,如果够不到母巢
creep.moveTo(Game.spawns['Spawn1']);//移动到母巢