当前位置: 首页 > backend >正文

Screeps Arena基础入门

本文主要内容

  • JavaSsript语法使用
  • VScode编译环境
  • Screeps Arena游戏规则

JavaSsript语法使用

        基本数据类型

// String, Numker,Boolean,null, undefined
const username = "John";
const age = 30;
const rate = 4.5;
const iscool = true;
const x = null;     #表示值为空指针
const y = undefined;   #表示根本不存在定义
let z;typeof   age

                字符串操作函数

const username = "John";
const age = 30;#字符串拼接
console.log("My name is " + username + " and I am age");
const hello = `My name is ${username} and I am ${age}`;
console.log(hello);const s = "Hello World!";#字符串操作
console.log(s.substring(0, 5).toUpperCase());
s.split("")   #不写东西的话就是切分最小

        引用数据类型

//const 确保了我们不能将 arr 指向一个新的数组,但可以修改数组内容。
//let 可以将arr 指向一个新数组,也可以修改数组内容。//声明数组
const fruits = ["apples", "oranges", "pears"];
fruits[3] = "grapes";
fruits.push("mangos");
fruits.unshift("strawberries");
fruits.pop();
console.log(Array.isArray("hello"));
console.log(fruits.indexof("oranges"));
console.log(fruits);//声明对象
const person = {firstName: "John",lastName: "Doe",age: 30,hobbies: ["music", "movies", "sports"],address: {street: "50 main st",city: "Boston",state: "MA",},
};
console.log(person.address.city);//解构属性  用相同的属性名
const{firstName,lastName,address: { city },
} = person;console.log(city);person.email = "john@gmail.com";  #直接增加属性

                对象数组和JSON转化

const todos = [{id: 1,text: "Take out trash",isCompleted: true,    },{id: 2,text: "Meeting with boss"isCompleted: true,},{id: 3,text: "Dentist appt",isCompleted: false,},
];const todoJSoN = JSoN.stringify(todos)
console.log(todoJsON);[{"id":1,"text":"Take outtrash","isCompleted":true},
{"id":2,"text":"Meeting with boss","isCompleted":true},
{"id":3,"text":"Dentist appt","isCompleted":false}]

        流程函数

const x = 4;//if判断函数
if (x === 10) {   #严格相等console.log("x is 10");
} else if (x > 10) {console.log("x is greater than 1o");
}else {console.log("x is less than 10");
}//三目运算符和switch函数
const color = x > 10 ? "red" : "blue";
switch (color) {case "red":console.log("color is red");break;case "blue":console.log("color is blue");break;default:console.log("color is Not red or blue");
}//for循环
for (let i = 0; i <= 10; i++) {console.log(`For Loop Number: ${i}`);
}//while循环
let i = 0;
while (i < 10){console.log(`While Loop Number: ${i}`);i++;
}

        总结内容

                数据类型

一、基本数据类型

  1. String(字符串)

    • 字符串可以用单引号(')或双引号(")来定义。

  2. Number(数字)

    • 用于表示整数或浮点数。

  3. Boolean(布尔值)

    • 只有两个值,true(真)和 false(假)。

  4. Undefined

    • 表示变量没有被赋值。例如:let x;,此时 x 的值为 undefined。当尝试访问一个未初始化的变量时,也会得到 undefined

  5. Null

    • 表示一个空值,是一个有意的空值。例如:let person = null;person 变量被赋予了 null 值,表明目前它没有指向任何对象或值。需要注意的是,null 是一个单独的值,并且和 undefined 不完全相同。

  6. BigInt(大整数)

    • 用于表示非常大的整数。例如:let bigNumber = 123456789012345678967890n;

二、引用数据类型(Object 对象)

  • 包括对象、数组和函数等。

    • 对象:是一个无序的键值对集合。例如:let person = {name: "John", age: 30};person 是一个对象,它有两个属性,nameage

    • 数组:是一种特殊类型的对象,用于存储有序的列表。例如:let arr = [1, 2, 3, 4, 5];arr 是一个数组,包含五个元素,可以通过索引访问数组中的元素。

    • 函数:其实也是对象的一种,它是可执行的代码块。例如:function add(a, b){return a + b;}

剩下的到Screeps Arena里面补充吧

VScode编译环境

VS Code 基础教程(一)—— VS Code 的基本使用入门-CSDN博客https://blog.csdn.net/weixin_46215588/article/details/110160065

Screeps Arena游戏规则

        入门10个关卡

Screeps Arena 游戏基础教程_screeps: arena-CSDN博客https://blog.csdn.net/weixin_50216991/article/details/137058456

1.循环和导入  (Loop and Import)
2.简单移动(Simple move)
3.首次攻击 (First Attack)
4.爬虫的身体部分(Creeps Bodies)
5.存储和转移(Store and Transfer)
6.地形(Terrain)
7.生产爬虫虫(Spawn Creeps)
8.收割能源(Harvest Energy)
9.建设 (Construction)
10.最终测试 (Final Test)

                通关代码

//主函数
export function loop() {// Your code goes here
}//移动农名
import { getObjectsByPrototype } from 'game/utils';
import { Creep, Flag } from 'game/prototypes';export function loop() {let creeps = getObjectsByPrototype(Creep);let flags = getObjectsByPrototype(Flag);creeps[0].moveTo(flags[0]);
}//攻击敌方农名
import { getObjectsByPrototype } from 'game/utils';
import { Creep } from 'game/prototypes';
import { ERR_NOT_IN_RANGE } from 'game/constants';export function loop() {let myCreep = getObjectsByPrototype(Creep).find(creep => creep.my);let enemyCreep = getObjectsByPrototype(Creep).find(creep => !creep.my);if(myCreep.attack(enemyCreep) === ERR_NOT_IN_RANGE) {myCreep.moveTo(enemyCreep);}
}//属性补充
MOVE:使爬虫移动; TOUGH :没有任何效果。
ATTACK:允许它近战范围内攻击;  RANGED_ATTACK:允许它攻击3格外的目标。
HEAL:允许治疗它自己或另一个爬虫。
WORK:可以建造建筑或收集能量; CARRY:增加爬虫携带资源的能力,身上可以携带更多的资源。//近战,远程,治疗
import { getObjectsByPrototype } from 'game/utils';
import { Creep } from 'game/prototypes';
import { ERR_NOT_IN_RANGE, ATTACK, RANGED_ATTACK, HEAL } from 'game/constants';export function loop() {let myCreeps = getObjectsByPrototype(Creep).filter(creep => creep.my);let enemyCreep = getObjectsByPrototype(Creep).find(creep => !creep.my);for(let creep of myCreeps) {if(creep.body.some(bodyPart => bodyPart.type == ATTACK)) {if(creep.attack(enemyCreep) == ERR_NOT_IN_RANGE) {creep.moveTo(enemyCreep);}}if(creep.body.some(bodyPart => bodyPart.type == RANGED_ATTACK)) {if(creep.rangedAttack(enemyCreep) == ERR_NOT_IN_RANGE) {creep.moveTo(enemyCreep);}}if(creep.body.some(bodyPart => bodyPart.type == HEAL)) {let myDamagedCreeps = myCreeps.filter(i => i.hits < i.hitsMax);if(myDamagedCreeps.length > 0) {if(creep.heal(myDamagedCreeps[0]) == ERR_NOT_IN_RANGE) {creep.moveTo(myDamagedCreeps[0]);}}}}
}//构造防御塔   这里container中立储能容器 和RESOURCE_ENERGY无尽能源
import { prototypes, utils, constants } from 'game';export function loop() {const tower = utils.getObjectsByPrototype(prototypes.StructureTower)[0];if(tower.store[constants.RESOURCE_ENERGY] < 10) {let myCreep = utils.getObjectsByPrototype(prototypes.Creep).find(creep => creep.my);if(myCreep.store[constants.RESOURCE_ENERGY] == 0) {let container = utils.getObjectsByPrototype(prototypes.StructureContainer)[0];myCreep.withdraw(container, constants.RESOURCE_ENERGY);} else {myCreep.transfer(tower, constants.RESOURCE_ENERGY);}} else {let target = utils.getObjectsByPrototype(prototypes.Creep).find(creep => !creep.my);tower.attack(target);}
}//不同地形
import { getObjectsByPrototype } from 'game/utils';
import { Creep, Flag } from 'game/prototypes';export function loop() {let creeps = getObjectsByPrototype(Creep).filter(i => i.my);let flags = getObjectsByPrototype(Flag);for(let creep of creeps) {let flag = creep.findClosestByPath(flags);creep.moveTo(flag);}
}//构造兵种
`MOVE`:50能量;`ATTACK`:80能量;`RANGED_ATTACK`:150能量
`HEAL`:250能量;`WORK`:100能量;`CARRY`:50能量;`TOUGH` :10能量//孵化兵种
import { getObjectsByPrototype } from 'game/utils';
import { Creep, Flag, StructureSpawn } from 'game/prototypes';
import { MOVE } from 'game/constants';let creep1, creep2;export function loop() {let mySpawn = getObjectsByPrototype(StructureSpawn)[0];let flags = getObjectsByPrototype(Flag);if(!creep1) {creep1 = mySpawn.spawnCreep([MOVE]).object;} else {creep1.moveTo(flags[0]);    if(!creep2) {creep2 = mySpawn.spawnCreep([MOVE]).object;} else {creep2.moveTo(flags[1]);}}
}//获取野外能量
import { prototypes, utils, constants } from 'game';export function loop() {let creep = utils.getObjectsByPrototype(prototypes.Creep).find(i => i.my);let source = utils.getObjectsByPrototype(prototypes.Source)[0];let spawn = utils.getObjectsByPrototype(prototypes.StructureSpawn).find(i => i.my);if(creep.store.getFreeCapacity(constants.RESOURCE_ENERGY)) {if(creep.harvest(source) == constants.ERR_NOT_IN_RANGE) {creep.moveTo(source);}} else {if(creep.transfer(spawn, constants.RESOURCE_ENERGY) == constants.ERR_NOT_IN_RANGE) {creep.moveTo(spawn);}}
}//构造建筑   一般只有塔
import { prototypes, utils } from 'game';
import { RESOURCE_ENERGY, ERR_NOT_IN_RANGE } from 'game/constants';export function loop() {const creep = utils.getObjectsByPrototype(prototypes.Creep).find(i => i.my);if(!creep.store[RESOURCE_ENERGY]) {const container = utils.findClosestByPath(creep, utils.getObjectsByPrototype(prototypes.StructureContainer));if(creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {creep.moveTo(container);}} else {const constructionSite = utils.getObjectsByPrototype(prototypes.ConstructionSite).find(i => i.my);if(!constructionSite) {utils.createConstructionSite(50,55, prototypes.StructureTower);} else {if(creep.build(constructionSite) == ERR_NOT_IN_RANGE) {creep.moveTo(constructionSite);}}}
}

        api文档

简介 | Screeps 中文文档https://screeps-cn.github.io/introduction.html

http://www.xdnf.cn/news/4838.html

相关文章:

  • 碰一碰发视频一键成片功能开发实践与技术解析
  • 字符宽度介绍
  • 仿LISP运算 - 华为OD机试真题(A卷、JavaScript题解)
  • 特征工程概述
  • QT 文件选择对话框 QFileDialog
  • DL/T645-2007电表协议简介以及请求应答帧格式
  • RSAC 2025观察:零信任+AI=网络安全新范式
  • 【HCIP】----OSPF综合实验
  • Day 14 训练
  • 雷赛伺服电机
  • 山东安全员A证的考试科目有哪些?
  • MySQL中隔离级别那点事
  • 主备Smart Link + Monitor Link组网技术详细配置
  • 【LeetCode】删除排序数组中的重复项 II
  • 2018机械行业ERP软件发展趋势
  • 从 ImageNet 到产业革命:AlexNet 作为破局者的三大核心创新及其时代穿透力
  • SKNet、空间注意力介绍
  • 1.MySQL数据库初体验
  • Matlab 基于Hough变换的人眼虹膜定位方法
  • Prometheus实战教程:k8s平台-node-exporter监控物理机
  • OPCUA,OPCDA与MODBUS学习笔记
  • RabbitMQ学习(第二天)
  • ConcurrentHashMap解析
  • 3中AI领域的主流方向:预测模型、强化学习和世界模型
  • Pytorch的简单介绍(起源、历史、优缺点、应用领域等等)
  • stable-diffusion windows本地部署
  • uniapp上架苹果APP Store踩雷和部分流程注意事项(非完整流程)
  • word文档基本操作: 编辑页眉页脚和插入目录
  • 移动端前端开发中常用的css
  • SQLite3常用语句汇总