本文共 4132 字,大约阅读时间需要 13 分钟。
# 你可以把字符串连起来,或者把数字连接到字符串中。# 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)
二营长,我的意大利炮呢,开炮!!
# 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!")
# 移动到 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)
# 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)
转载地址:http://txie.baihongyu.com/