
CodeCombat代码全记录(Python学习利器)--边地森林(第二章)代码11
发布日期:2021-05-07 10:58:08
浏览次数:23
分类:原创文章
本文共 3127 字,大约阅读时间需要 10 分钟。
Chameleons(伪装者)
# Ogres are disguised as coins or gems!while True: enemy = hero.findNearestEnemy() # If you see an enemy - attack it: if enemy: hero.attack(enemy) item = hero.findNearestItem() # If you see a coin or a gem - move to it's X and Y position: if item: hero.moveXY(item.pos.x, item.pos.y)
Arrowproof Wolf(无箭狼)
# Collect mushrooms.# First, come to the wolf pet and wake up it (say).hero.moveXY(12, 34)hero.say("Weak Up wolf!!")# Next collect mushrooms just usual items.while True: item = hero.findNearestItem() if item: hero.moveXY(item.pos.x, item.pos.y)
攻擊和凍住你的敵人
# 你掉进陷阱里了!别动!你会受伤的!# 这个函数检查敌人是否再攻击范围。def inAttackRange(enemy): distance = hero.distanceTo(enemy) # Almost all swords have attack range of 3. if distance <= 3: return True else: return False# Attack ogres only when they're within reach.while True: # 找到最近的敌人,并将其储存在一个变量中。 enemy = hero.findNearestEnemy() # 调用 inAttackRange(enemy),将 enemy 作为参数 # 把结果保存于 “canAttack” 变量中 canAttack = inAttackRange(enemy) # If the result stored in canAttack is True, 然后下手! if canAttack is True: hero.attack(enemy) pass
多人宝藏森林(挑战关卡)
我使用了和平共处的五项原则,没有对电脑下手,挑战关卡,大家可以进行自己的代码编写。这里我就简单编写了。
关于旗子的使用,后面会有很多的练习关卡,让我们多加练习如何使用旗子。
# 当第一个收集100个金币的人!# 如果你死了,重生的时候只有原来67%的金币while True: # 找到金币并攻击敌人 # 使用旗子和特殊的移动策略来赢得比赛! coin = hero.findNearestItem() enemy = hero.findNearestItem() #flag = hero.findFlag() if coin: hero.moveXY(coin.pos.x, coin.pos.y)
围攻Stonehold(挑战开放关卡)
之后此类关卡先不编写内容,大家自行编写,后续我们会统一用开放式的思想进行此类关卡的内容编写。
并且此类关卡涉及到自身血量的问题,后续的关卡我们也会练习到。如果你不会定义血量等内容,那先使用你的砖石购买些好的装备,来称下血量。
为援兵坚持住
旗子练习关卡!!注意,旗子关卡你需要提交后才可以使用旗子控制英雄!!
# 食人魔正在爬悬崖# 为集结民兵组织保护足够长时间的农民。while True: flag = hero.findFlag() enemy = hero.findNearestEnemy() if flag: # 捡旗子 hero.pickUpFlag(flag) elif enemy: # 否则,攻击! # 使用旗子移动到指定位置,如果 “cleave” 技能冷却完毕,就使用 “cleave” 技能。 if hero.isReady("cleave"): hero.cleave(enemy) else: hero.attack(enemy)
赚钱行家
# To make the training more interesting Senick poisoned you.# While you aren't moving the poison is harmless.# This function should check if a coin is closer than 20m.def isCoinClose(coin): # Find the distance to the coin. distanceToCoin = hero.distanceTo(coin) # If the distance is less than 20: if distanceToCoin < 20: # Return True return True # Else: else: # Return False return False passwhile True: item = hero.findNearestItem() if item: # If isCoinClose(item) returns true: if isCoinClose(item): hero.moveXY(item.pos.x, item.pos.y)
盐碱地
# Ogres are attacking a nearby settlement!# 小心,兽人在地上放了毒药。# Gather coins and defeat the ogres, but avoid the burls and poison!while True: enemy = hero.findNearestEnemy() if enemy.type == "munchkin" or enemy.type == "thrower": hero.attack(enemy) item = hero.findNearestItem() # 检查物品类型,确保英雄不会捡起毒药! # Look for types: 'gem' or 'coin' if item.type == "gem" or item.type == 'coin': hero.moveXY(item.pos.x, item.pos.y)
发表评论
最新留言
路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月23日 21时35分07秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
我编程,我快乐—程序员职业规划之道
2019-03-05
谷歌浏览器如何设置不阻止弹窗弹出
2019-03-05
TCP/IP协议头
2019-03-05
stringstream常见用法介绍
2019-03-05
剑指 Offer 29. 顺时针打印矩阵
2019-03-05
电梯,游戏签到,黑板测试点
2019-03-05
我的CSDN 图床
2019-03-05
python_遍历操作
2019-03-05
天池大赛o2o优惠券第一名代码解读_xgboost方式
2019-03-05
Web基础应用 NFS服务基础 触发挂载
2019-03-05
DNS服务基础 特殊解析 DNS主从架构 DNS子域授权 DNS查询
2019-03-05
python_透视表操作unstack
2019-03-05
端口列表_端口占用问题解决kill_ps_net
2019-03-05
create-react-app路由的实现原理
2019-03-05
PSI值
2019-03-05
lift曲线
2019-03-05
【java方法】代码练习——程序逻辑控制
2019-03-05
字符串与数组的转化的简单易懂的方法
2019-03-05
中缀表达式与后缀表达式
2019-03-05