
CodeCombat代码全记录(Python学习利器)--边地森林(第二章)代码10
发布日期:2021-05-07 10:58:06
浏览次数:13
分类:原创文章
本文共 4132 字,大约阅读时间需要 13 分钟。
从本章节之后,我们开始学习数字内容相关的知识,更进一步熟悉python中的四则运算,注意多看下提示!!
德雅啤酒(似曾相识的味道)
# 你可以把字符串连起来,或者把数字连接到字符串中。# Sing along, using string concatenation:# X potions of health on the wall!# X potions of health!# Take Y down, pass it around!# X-Y potions of health on the wall.potionsOnTheWall = 10numToTakeDown = 1while True: hero.say(potionsOnTheWall + " potions of health on the wall!") # 唱出下一句: hero.say(potionsOnTheWall + " potions of health!") # 唱出下一句: hero.say("Take" + numToTakeDown + " down, pass it around!") potionsOnTheWall -= numToTakeDown # 唱出最后一句: hero.say(potionsOnTheWall + " potions of health on the wall!")
巫师之门
# Move to Laszlo and get his secret number.hero.moveXY(30, 13)las = hero.findNearestFriend().getSecret()# 向 Laszlo 的数字中加7就能得到 Erzsebet的号码# Move to Erzsebet and say her magic number.erz = las + 7hero.moveXY(17, 26)hero.say(erz)# 将 Erzsebet 的数字除以 4 得到 Simoyi 的数字。# Go to Simonyi and tell him his number.sim = erz / 4hero.moveXY(30, 39)hero.say(sim)# 将 Simonyi 的数字乘以 Laszlo 的数字得到 Agata 的数字。# Go to Agata and tell her her number.aga = sim * lashero.moveXY(43, 26)hero.say(aga)
Backwoods Bombardier(边地投弹)
二营长,我的意大利炮呢,开炮!!
# The pos property is an object with x and y properties.# pos.x is a number representing the horizontal position on the map# pos.y is a number representing the vertical position on the mapwhile True: enemy = hero.findNearestEnemy() if enemy: x = enemy.pos.x # Get the enemy's y position! y = enemy.pos.y # ∆ Change this! # say the x and y position separated by a comma hero.say(x + "," + y) else: hero.say("Cease" + " Fire!")
The Wizard’s Haunt(巫师出没)
# 移动到 Zsofia 的身边,从他那得到秘密号码hero.moveXY(18, 20)zso = hero.findNearestFriend().getSecret()# 将 Zsofia 的数字除以 4 得到 Mihaly 的数字。# Move to Mihaly and say his magic number.mih = zso / 4hero.moveXY(30, 15)hero.say(mih)# 把 Mihaly 的号码除以5来得到 Beata 的号码# Move to Beata and say her magic number.bea = mih / 5hero.moveXY(42, 20)hero.say(bea)# 将 用'Mihaly'的数字减去'Beata'的数字,来得到 Sandor 的数字。。# Move to Sandor and say his magic number.san = mih - beahero.moveXY(38, 37)hero.say(san)
金币屑
# 跟随硬币的轨迹来到红色 X 标记的出口while True: # 这能找到最近的敌人。 item = hero.findNearestItem() if item: # 这将物品的 pos,就是坐标,存储在变量中。 itemPosition = item.pos # 将物品的 X 和 Y 坐标放进变量。 itemX = itemPosition.x itemY = itemPosition.y # Now, use moveXY to move to itemX and itemY: hero.moveXY(itemX, itemY)
The Wizard’s Plane(巫师天际层)
# Move to Eszter and get the secret number from her.hero.moveXY(16, 32)esz = hero.findNearestFriend().getSecret()# Multiply by 3 and subtract 2 to get Tamas's number.# Remember to use parentheses to do calculations in the right order.# Move to Tamas and say his magic number.tam = (esz * 3) - 2hero.moveXY(24, 28)hero.say(tam)# Subtract 1 and multiply by 4 to get Zsofi's number.# Move to Zsofi and say her magic number.zso = (tam - 1) * 4hero.moveXY(32, 24)hero.say(zso)# Add Tamas's and Zsofi's numbers, then divide by 2 to get Istvan's number.# Move to Istvan and say his magic number.ist = (tam + zso) / 2hero.moveXY(40, 20)hero.say(ist)# Add Tamas's and Zsofi's numbers. Subtract Istvan's number from Zsofi's. Multiply the two results to get Csilla's number.# Move to Csilla and say her magic number.csi = (tam + zso) * ( zso - ist)hero.moveXY(48,16)hero.say(csi)
白兔
# 跟随发光石引导陷阱while True: item = hero.findNearestItem() if item: # 使用 item.pos 将物品位置保存为一个新的变数 # 使用 pos.x 和 pos.y 保存坐标 x = item.pos.x y = item.pos.y # 使用 moveXY() 和 X 与 Y 变数移动至坐标 hero.moveXY(x, y) pass
未知的距离
# 你的任务是告诉他兽人的距离。# 这个函数寻找最近的敌人,并返回距离。# If there is no enemy, the function returns 0.def nearestEnemyDistance(): enemy = hero.findNearestEnemy() result = 0 if enemy: result = hero.distanceTo(enemy) return resultwhile True: # Call nearestEnemyDistance() and # save the result in the variable enemyDistance. enemyDistance = nearestEnemyDistance() # If the enemyDistance is greater than 0: if enemyDistance > 0: # Say the value of enemyDistance variable. hero.say(enemyDistance)
发表评论
最新留言
表示我来过!
[***.240.166.169]2025年03月23日 12时10分34秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
jquery each 操作批量数据
2019-03-04
Mac OS X 下 su 命令提示 sorry 的解决方法
2019-03-04
vue-router 缓存路由组件对象
2019-03-04
js中事件捕获和事件冒泡(事件流)
2019-03-04
js的各种数据类型判断(in、hasOwnProperty)
2019-03-04
严格模式、混杂模式与怪异模式
2019-03-04
一篇文章带你搞定 Java 中字符流的基本操作(Write / Read)
2019-03-04
HTML 和 CSS 简单实现注册页面
2019-03-04
(Java)让枚举实现一个接口
2019-03-04
XML 解析学习
2019-03-04
验证码的简单实现
2019-03-04
JSP 入门学习
2019-03-04
JSP,EL 和 JSTL 一篇文章就够了
2019-03-04
(延迟初始化)Lazy 初始化
2019-03-04
(SpringMVC)springMVC.xml 和 web.xml
2019-03-04
Oracle 学习一篇文章就够了(珍藏版)
2019-03-04
一篇文章带你搞定 Oracle 的体系结构
2019-03-04
Oracle 单行函数
2019-03-04
(Java 剑指 offer)剪绳子
2019-03-04
一篇文章带你搞定 OAuth 2.0 的四种方式
2019-03-04