codecombat安息之云山峰1-10关及森林47/48关代码分享

codecombat中国游戏网址:
http://www.codecombat.cn/

所有代码为javascript代码分享

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1、峭壁追逐

// 抓住 Pender Spellbane 去了解她的秘密。

loop {

// Pender是这里唯一的朋友,所以她总是在最近的位置。

pender = this.findNearest(this.findFriends());

if (pender) {

// moveXY()将移动到 Pender 在的位置,

// 但是她会向远离你的位置移动。

//this.moveXY(pender.pos.x, pender.pos.y);

// move()只一次移动一步。

// 所以你可以用它来追踪你的目标。

this.move(pender.pos);

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2、激流回旋

// 使用对象枚举来走安全的路,并收集宝石。

// 在本关你不能够使用 moveXY()方法!使用 move()来移动

gems = this.findItems();

while (this.pos.x < 20) {

// move()移动物体通过 x 和 y 的属性,不仅仅是数字。

this.move({‘x‘: 20, ‘y‘: 35});

}

while (this.pos.x < 25) {

// 一个宝石的位置是一个对象,有 x 和 y 属性。

gem0 = gems[0];

this.move(gem0.pos);

}

while (this.pos.x < 30) {

// 当你的 x 小于30的时候,

// 使用物体移动到30,35位置

this.move({‘x‘: 30, ‘y‘: 35});

}

while (this.pos.x < 35) {

// 当你的 x 小于35的时候

// 移动到宝石[1]的位置

gem1 = gems[1] ;

this.move(gem1.pos);

}

// 拿到最后一对宝石!

while (this.pos.x < 40) {

this.move({‘x‘: 40, ‘y‘: 35});

}

while (this.pos.x < 45) {

gem2 = gems[2] ;

this.move(gem2.pos);

}

while (this.pos.x < 50) {

this.move({‘x‘: 50, ‘y‘: 35});

}

while (this.pos.x < 55) {

gem3 = gems[3] ;

this.move(gem3.pos);

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3、食人魔山谷挖宝

// 一大群食人魔来之前你只有20秒时间!

// 尽可能去捡金币,然后你撤退到你栅栏后面的基地里!

while(this.now() < 20) {

// 收集金币

var gold = this.findItems();

var values = 99999 ;

var golds = 0 ;

var mostval = null ;

while (golds < gold.length) {

var g = gold[golds] ;

var v = this.distanceTo(g)/g.value ;

if ( v < values) {

values = v;

mostval = g ;

}

golds ++ ;

}

this.moveXY(mostval.pos.x, mostval.pos.y);

}

while(this.pos.x > 16) {

// 撤退到栅栏后面

this.say("我应该撤退");

this.moveXY(16, 38);

}

// 建立栅栏挡住食人魔

this.buildXY("fence", 21, 36);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4、黑钻石

loop {

var gem = this.findNearest(this.findItems());

if (gem) {

var clear = this.isPathClear(this.pos, gem.pos);

// isPathClear 方法告诉你是否有障碍物在路上

// 如果是通畅的,move()到 gem.pos (宝石的位置)

if (clear) {

this.move(gem.pos);

}

// 否则的话,回到中心点。

else {

this.move({x:40, y:35});

}

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

5、宝藏洞穴

// 比起立即杀死食人魔,更好的选择是只躲避雪人。

// 5秒后我们会攻击你的火焰陷阱。

// 清空北面的地区,将会是一个很好的爆炸引诱的地点。

// 雪人不会一直被引开,所以快点偷金币!

loop {

var flagg = this.findFlag("green");

var flagb = this.findFlag("black");

if (flagb) {

this.buildXY("fire-trap", flagb.pos.x, flagb.pos.y);

this.pickUpFlag(flagb);

}

if (flagg) {

this.pickUpFlag(flagg);

}

var item = this.findNearest(this.findItems());

if (item) {

this.move(item.pos);

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

6、跳舞人生

// 和你的舞伴同步移动让 Pender Spellbane 印象深刻。

var nearest = this.findNearest(this.findFriends());

var disx = this.pos.x - nearest.pos.x ;

var disy = this.pos.y - nearest.pos.y ;

loop {

var x = nearest.pos.x + disx ;

var y = nearest.pos.y + disy ;

this.moveXY(x, y);

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

7、安息之云指挥官

// 召唤一些士兵,然后引导他们去你的基地。

// 每个士兵消耗20金币。

while (this.gold > this.costOf("soldier")) {

this.summon("soldier");

}

// 添加一个while 循环来命令所有的士兵。

soldiers = this.findFriends();

soldierIndex = 0;

while (soldierIndex < soldiers.length) {

soldier = soldiers[soldierIndex];

this.command(soldier, "move", {x: 50, y: 40});

soldierIndex ++ ;

}

// 去加入你的朋友!

this.moveXY(44, 42);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

8、高山拉力

//购买帮助中指定的法师和带haste的二级法典

// 逃离右边的地图

// 为了逃脱的雪人,你必须让自己更快。

// 使用resetCooldown来施法更频繁

// manaBlast能帮我们清理道路

this.cast("haste", this);

this.resetCooldown("haste");

this.moveXY(109, 36);

this.manaBlast();

this.moveXY(155, 37);

this.cast("haste", this);

this.moveXY(273, 37);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

9、唯利是图山

// 收集金币召唤士兵,让他们攻击敌人。

this.cast("shrink", this);

loop {

// 移动到最近的金币处。

// 使用 move 取代 moveXY,以便于你可以不断发出命令。

var item = this.findNearest(this.findItems());

if (item) {

this.move(item.pos);

}

// 如果你有足够的资金召唤士兵,就召唤一个。

if (this.gold > this.costOf("soldier")) {

this.summon("soldier");

}

var enemy = this.findNearest(this.findEnemies());

if (enemy) {

// 遍历你所有的士兵,命令他们攻击。

var soldiers = this.findFriends();

var soldierIndex = 0;

while (soldierIndex < soldiers.length) {

var soldier = soldiers[soldierIndex];

this.command(soldier, "attack", enemy);

soldierIndex ++ ;

}

// 使用 attack 命令让你的士兵们攻击。

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

10、木材守卫

loop {

// 收集金子

var golds = this.findNearest(this.findItems());

if (golds) {

this.move(golds.pos);

}

// 如果你有足够的金币,召唤一个士兵。

if (this.gold > this.costOf("soldier")) {

this.summon("soldier");

}

// 使用 for 循环来命令每个士兵。

var friends = this.findFriends();

// for 循环用三个部分,用分号分隔开。

// for(初始化;条件;表达式)

// 初始化是在第一次循环开始时完成的。

// 当条件为真的时候,循环继续

for(var friendIndex = 0; friendIndex < friends.length; friendIndex++)     {

var friend = friends[friendIndex];

if(friend.type == "soldier") {

var enemy = friend.findNearestEnemy();

// 如果这有一个敌人,命令她攻击。

// 否则的话,移动她到地图的右边。

if (enemy) {

this.command(friend, "attack", enemy);

}

else {

this.command(friend, "move", {x: 80, y: 45});

}

}

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

番外篇:森林47关-博尔德森林

// 使用 isPathClear 命令来在随机位置的巨石周围移动

// 自动寻路不能在本关使用

loop {

var angle = Math.PI / 2 - Math.PI / 16;

while (angle >= -Math.PI / 2) {

var targetX = this.pos.x + 5 * Math.cos(angle);

var targetY = this.pos.y + 5 * Math.sin(angle);

// 使用 isPathClear 命令在你当前的位置和目标中间

// 如果道路是干净的,可以移动到目标

if (this.isPathClear(this.pos, {x: targetX, y:targetY})) {

this.moveXY(targetX, targetY);

}

else {

// 否则的话,转一个角度再尝试。

angle -= Math.PI / 16;

}

}

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

番外篇:森林48关-超级大的小食人魔 攻击

// That‘s a big‘un! With some clever thinking, Ivy should be able to take care of this situation single-handedly.

var x1 = 44 ;

var y1 = 34 ;

loop {

// Find the archer.

var friend = this.findNearest(this.findFriends());

var enemy = this.findNearest(this.findEnemies());

// Tell the archer to attack the enemy!

if(friend && enemy) {

this.command(friend, "attack", enemy);

}

// Wait, no, that doesn‘t work that well. Maybe try something else?

// The munchkin is awfully slow...

if (enemy) {

if (friend.distanceTo(enemy) < 15) {

this.command(friend, "move", {x: x1, y: y1});

}

}

x1 -= 10 ;

y1 -= 10 ;

}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

时间: 2024-08-15 05:35:53

codecombat安息之云山峰1-10关及森林47/48关代码分享的相关文章

codecombat安息之云山峰37-40关及地牢42关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 37.Deadly Discs //要有足够的钱买新英雄,大约是4800左右 // If the ogre takes damage, she'll wake up and smash the peasant. // You've got these razor-discs you can throw(). M

codecombat安息之云山峰11-21关及沙漠38关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11.零和 // 在两分钟内击败敌方英雄. loop { var enemies = this.findEnemies(); var nearestEnemy = this.findNearest(enemies); var item = this.findNearest(this.findIte

codecombat安息之云山峰32-36关及森林49关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 32.Sowing Fire // Goal: build three rows of nine fire-traps. // Returns "retreat", "attack", "start-next-trap-column", or "bui

codecombat安息之云山峰41关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 41.Summit's Gate //需要一个好的操作 // Fight your way into the Inner Sanctum of the ogre chieftain, and kill her. this.flags = function(){ var flagg = this.findFlag

codecombat安息之云山峰22-31关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 22.躁动的死亡 // 这个关卡应该是非常难的!你也许需要一个很棒的战略与或装置去完成它! // 找到然后杀死雪人,为了仪式去收集他的血液. // 你也许想收集雪人遗留下的金币,你需要他们去召唤一只军队. // 站在召唤石旁(红色X),开始召唤. // this.flags = function(){ var 

高并发之Memcached实战第10课-“Memcached Get获取数据”部分代码分享2

高并发之Memcached实战第10课-"Memcached Get获取数据"部分代码分享2 一.Memcached客户端读写在同一个程序的逻辑: MemcachedClient mcc = new MemcachedClient(list); if(mcc.get("something")==null) { if(!DataFactory.Exist(somethingObject)) { DataFactory.StoreInDB(somethingObject

codecombat之Sarven沙漠13-24关及森林45/46关代码分享

codecombat中国游戏网址:http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 13.诱饵钻 // 我们在测试一个新的战斗单位:诱饵. // 创建4个诱饵,然后汇报给 Naria var decoysBuilt = 0; loop { var item = this.findNearest(this.findItems()); // 掠夺金币! var x = item.pos

腾讯云短信服务使用记录与.NET Core C#代码分享

1.即使是相同的短信签名与短信正文模板,也需要针对“国内文本短信”与“海外文本短信”分别申请.开始不知道,以为只要申请一次,给国外手机发短信时给api传对应的国家码就行,后来才发现需要分别申请. 2.短信服务web api响应“手机号内容频率限制”错误.这是由于在30秒内向同一手机号多次发送了相同内容的短信,这是腾讯云短信服务的默认限制——“相同内容短信对同一个手机号,30秒内发送短信条数不超过1条”,可以通过“应用配置”的“短信频率配置”修改这个限制. 3.腾讯云短信服务没有提供 .NET C

codecombat之边远地区的森林31-44关代码分享

codecombat中国游戏网址: http://www.codecombat.cn/ 所有代码为javascript代码分享 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 31.为援兵坚持住 // 食人魔正在爬悬崖 // 为集结民兵组织保护足够长时间的农民. loop { var flag = this.findFlag(); var enemy = this.findNearestEnemy(); if (flag) { // 捡旗子 this.pickUpFla