返回官网

screeps 页面javascript游戏代码以及文档地址

狒狒 2023-11-6 技术札记 439 次

//https://screeps-cn.github.io/api/#Game.creeps

//https://screeps.com/a/#!/sim/tutorial/1






module.exports.loop = function () {


    for(var name in Game.creeps) {
        var creep = Game.creeps[name];
        //采集者则进行采集的操作
        if(creep.memory.role == 'harvester') {
            roleHarvester.run(creep);
        }
        if(creep.memory.role == 'upgrader') {
            roleUpgrader.run(creep);
        }
        if(creep.memory.role == 'builder') {
            roleBuilder.run(creep);
        }
    }
  
}
// for(var rob=2;rob<30;rob++){
//  Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, MOVE], 'harvester3', {
//         memory: {role: 'harvester'}
//     });
// }
// for(var rob=2;rob<10;rob++){
// Game.spawns['Spawn1'].spawnCreep( [WORK, CARRY, MOVE], 'Builder'+rob,
//     { memory: { role: 'builder' } } );
// }    
    
 
 
 
var tower = Game.getObjectById('693092d10bdaba0a44c94e45');
if(tower) {
    //寻找不属于我们自己的细胞,并且攻击他
    var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
    if(closestHostile) {
        tower.attack(closestHostile);
    }
}
    
    
    
var roleBuilder = {

    /** @param {Creep} creep **/
    run: function(creep) {
        //当为建造,但没有能量的时候,身份切换为采集
        if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
            creep.memory.building = false;
            creep.say('

发表评论

Copyright © 2016 DEWEBSTUDIO