🏃 1. 英雄基础 (移动与状态)
让英雄直接走到指定的坐标 (x, y)。在到达前他不会停下!
hero.moveXY(24, 35)
hero.moveXY(24, 35);
只走一小步!通常用于复杂的路径计算或在移动中攻击。
hero.move({"x": 24, "y": 35})
hero.move({24, 35});
💡 小提示: moveXY 是自动导航,move 是手动驾驶。
了解你自己!这些属性帮你做判断。
hero.gold: 你有多少钱?(每秒+3金币/控制点)
hero.health / hero.maxHealth: 生命值。
hero.pos: 你的位置 {x, y}。
hero.team: 你是 "humans" (人类) 还是 "ogres" (食人魔)?
hero.maxSpeed: 你跑得有多快?(当前: 4 m/s)
hero.time: 比赛进行了多少秒。
👀 2. 慧眼识局 (感知环境)
找到离你最近的那个坏蛋。
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
auto enemy = hero.findNearestEnemy();
if (enemy) {
hero.attack(enemy);
}
找到所有特定类型的单位。比如找出所有的 "thrower" (投矛手)。
# 找到所有敌人
enemies = hero.findEnemies()
# 从敌人中筛选出投矛手
throwers = hero.findByType("thrower", enemies)
auto enemies = hero.findEnemies();
auto throwers = hero.findByType("thrower", enemies);
hero.findEnemies(): 找到所有活着的敌人。
hero.findFriends(): 找到所有活着的队友。
hero.findItems(): 找到所有物品(金币、药水)。
hero.findEnemyMissiles(): 警报!看到飞来的箭和炮弹。
hero.hasEffect(effect): 检查自己是否中毒或被减速。
⚔️ 3. 巨人战斗 (Goliath 专属)
普通攻击。伤害很高 (56.25)!
hero.attack(enemy)
hero.attack(enemy);
战争践踏! 造成100点伤害并击退周围15米内的敌人。冷却10秒。
if hero.isReady("stomp"):
hero.stomp()
if (hero.isReady("stomp")) {
hero.stomp();
}
🔥 爽快时刻: 被一群小兵包围时使用效果最佳!
把敌人抓起来扔出去!可以扔到身后,也可以扔到指定位置。
# 把敌人扔到 (20, 40)
hero.hurl(enemy, {"x": 20, "y": 40})
hero.hurl(enemy, {20, 40});
向远处扔出一枚炮弹。需要目标在 hero.throwRange (25米) 内。
hero.throwPos({"x": 40, "y": 40})
hero.throwPos({40, 40});
🚩 4. 运筹帷幄 (控制点)
胜利的关键: 地图上有7个控制点。派单位站在控制点10米范围内,就能占领它!占领越多,金币越多 (每个点每秒 +3 金币)。
返回所有控制点的数组。每个点包含:name (名称), pos (坐标), team (归属)。
points = hero.getControlPoints()
for point in points:
# 如果这个点不是我的,就去占领!
if point.team != hero.team:
hero.moveXY(point.pos.x, point.pos.y)
auto points = hero.getControlPoints();
for (auto point : points) {
if (point.team != hero.team) {
hero.moveXY(point.pos.x, point.pos.y);
}
}
返回一个对象(字典),可以直接用名字查坐标。名字如 "center", "nearA", "farB"。
⚠️ 注意: 无论你是红方还是蓝方,系统会自动反转 "near" (近) 和 "far" (远),保证代码通用。
🏰 5. 统帅三军 (召唤与指挥)
只要金币够,就能召唤军队!
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
if (hero.gold > hero.costOf("soldier")) {
hero.summon("soldier");
}
不要让士兵闲着!
指令: "move", "attack", "defend", "attackPos"。
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", friend.findNearestEnemy())
auto friends = hero.findFriends();
for (auto friend : friends) {
hero.command(friend, "attack", friend.findNearestEnemy());
}
📊 兵种数据表 (Unit Stats)
| 单位 |
类型 |
花费 💰 |
血量 ❤️ |
特点 |
| Soldier (士兵) |
"soldier" |
20 |
200 |
基础肉盾,速度中等 |
| Archer (弓箭手) |
"archer" |
25 |
30 |
远程高攻,血很少 |
| Artillery (火炮) |
"artillery" |
75 |
100 |
超远射程 (65m),范围伤害! |
| Arrow Tower (箭塔) |
"arrow-tower" |
100 |
600 |
不能移动,自动防守 |
🧠 6. 逻辑大脑 (编程概念)
while-true loop: 无限循环,游戏的核心引擎。
for-loop / for-in-loop: 遍历数组(如敌人列表、控制点列表)。
if/else: 决策核心。"如果血量低,就跑;否则,就打"。
break / continue: 控制循环的停止或跳过。