极客战记-平常的一天
1、选择英雄和编程语言
2、选择装备
3、写中文注释
1、写代码
2、运行
1、写代码
// 打败食人魔,收集金币。一切都那么平常。
// 使用 与(AND) 在同一行检查存在性和类型。
while (true) {
var enemy = hero.findNearestEnemy();
// 有了与(AND),只在敌人存在时检查类型
if (enemy && enemy.type == "munchkin") {
hero.attack(enemy);
}
// 寻找最近的物品
var coin = hero.findNearestItem();
// 如果有类型为 “coin” (金币)的物品存在,那就快去收集它!
if(coin && coin.type=="coin") {
hero.moveXY(coin.pos.x, coin.pos.y);
}
}
2、运行
1、写代码
# 打败食人魔,收集金币。一切都那么平常。
# 使用 与(AND) 在同一行检查存在性和类型。
while true
enemy = hero.findNearestEnemy()
# 有了与(AND),只在敌人存在时检查类型
if enemy and enemy.type == "munchkin"
hero.attack(enemy)
# 寻找最近的物品
a=hero.findNearestItem()
if a and a.type=="coin"
hero.moveXY(a.pos.x, a.pos.y)
# 如果有名为 “coin” (金币)的物品存在,那就快去收集它!
2、运行
1、写代码
-- 打败食人魔,收集金币。一切都那么平常。
-- 使用 与(AND) 在同一行检查存在性和类型。
while true do
local enemy = hero:findNearestEnemy()
-- 有了与(AND),只在敌人存在时检查类型
if enemy and enemy.type == "munchkin" then
hero:attack(enemy)
end
-- 寻找最近的物品
local item = hero:findNearestItem()
-- 如果有类型为 “coin” (金币)的物品存在,那就快去收集它!
if item and item.type == "coin" then
hero:moveXY(item.pos.x, item.pos.y)
end
end
2、运行