codecombat计算机科学⼊门三(Python)1.友⼈和敌⼈
while True:
friend = hero.findNearestFriend()
if friend:
hero.say("To battle, " + friend.id + "!")
# 寻最近的敌⼈,然后让他们
enemy = hero.findNearestEnemy()
if enemy:
hero.say("Go away, " + enemy.id)
2.德雅啤酒
# <%= plus %>
# <%= 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 = 10
numToTakeDown = 1
while True:
hero.say(potionsOnTheWall + " potions of health on the wall!")
# <%= song %>
hero.say(potionsOnTheWall + " potions of health!")
# <%= song %>
hero.say("Take " + numToTakeDown + " down, pass it around!")
potionsOnTheWall -= numToTakeDown
# <%= last %>
hero.say(potionsOnTheWall + " potions of health on the wall.")
3.Reward  and Ruination
while True:
enemy = hero.findNearestEnemy()
if enemy:
enemyPos = enemy.pos.x + " " + enemy.pos.y
hero.say("Enemy at " + enemyPos)
# Now that you have sweet revenge,
# why not have your cake and eat it, too?
# Find the item's position and
# say it for your artillery to target.
item = hero.findNearestItem()
if item:
itemPos = item.pos.x + " " + item.pos.y
hero.say("Item at " + itemPos)
Concept Challenge. Air Rescue Service
# To save a friend: say "Friend " followed by the friend's id property. # To zap an enemy: say "Enemy " followed by the enemy's id property. while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.say("Enemy " + enemy.id)
friend = hero.findNearestFriend()
if friend:
hero.say("Friend " + friend.id)
4. 巫师之门
# <%= secret_number %>
las = hero.findNearestFriend().getSecret()
# <%= instr_erzsebet %>
# <%= move_erzsebet %>
erz = las + 7
hero.say(erz)
# <%= instr_simonyi %>
# <%= move_simonyi %>
sim = erz / 4
hero.say(sim)
# <%= instr_agata %>
# <%= move_agata %>
aga = sim * las
hero.say(aga)
5. The Wizard's Haunt
# <%= secret_number %>
zso = hero.findNearestFriend().getSecret()
# <%= instr_mihaly %>
# <%= move_mihaly %>
mih = zso / 4
hero.say(mih)
# <%= instr_beata %>
# <%= move_beata %>
bea = mih / 5
hero.say(bea)
# <%= instr_sandor %>
# <%= move_sandor %>
san = mih - bea
hero.say(san)
6. The Wizard's Plane
# Move to 'Eszter' and get the secret number from her.
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) - 2
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) * 4
hero.say(zso)
python新手代码你好# 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) / 2
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.say(csi)
Concept Challenge. True Alchemy
# You are given the number of gold, silver and bronze coins.
# Save the result of each mathmatical operation into a variable, and say the result at each step.
wizard = hero.findNearestFriend()
goldCoins = ldCoins
silverCoins = wizard.silverCoins
bronzeCoins = wizard.bronzeCoins
# Add the number of gold and silver coins, then say the result.
sum = goldCoins + silverCoins
hero.say(sum)
# Subtract bronze coins from the previous result, then say the new result.
sub = sum - bronzeCoins
hero.say(sub)
# Divide the previous result by 3, then say the new result.
div = sub / 3
hero.say(div)
# Multiply the previous result by 2, then say the new result.
mult = div * 2
hero.say(mult)
7. ⾦币屑
# <%= escape_room %>
while True:
# <%= find_item %>
item = hero.findNearestItem()
if item:
# <%= get_pos %>
itemPosition = item.pos
# <%= get_x_y %>
itemX = itemPosition.x
itemY = itemPosition.y
# <%= move_take %>
8. ⽩兔
# 跟随发光⽯引导陷阱
while True:
item = hero.findNearestItem()
if item:
# 使⽤ item.pos 将物品位置保存为⼀个新的变数
position = item.pos
# 使⽤ pos.x 和 pos.y 保存坐标
x = position.x
y = position.y
# 使⽤ moveXY() 和 X 与 Y 变数移动⾄坐标
9. 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:
pos = item.pos
Concept Challenge. Rich and Safe
# Find items and move to their position.
while True:
item = hero.findNearestItem()
if item:
Combo Challenge. Wind Correction
# Say the x,y position of ogres as two numbers separated by a comma. # For better accuracy, subtract 4 from the y position before saying it. while True:
enemy = hero.findNearestEnemy()
if enemy:
y = enemy.pos.y - 4
hero.say(enemy.pos.x + "," + y)
10. 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 map
while True:
enemy = hero.findNearestEnemy()
if enemy:
x = enemy.pos.x
y = enemy.pos.y
# say the x and y position separated by a comma
hero.say(x + "," + y)
else:
hero.say("Cease" + " " + "Fire!")
11. 收集⾦币
# 当你放好旗帜后点提交。
# 点击提交后,旗帜按钮出现在左下⾓.
while True:
flag = hero.findFlag()
if flag:
hero.pickUpFlag(flag)
else:
hero.say("为英雄放置⼀⾯旗帜来移动.")
12. ⾦币草地
# 收集每⽚草地的所有⾦币。
# 使⽤旗⼦在草地间移动。
# 当你准备好放置旗⼦时点击“提交”
while True:
flag = hero.findFlag()
if flag:
# 捡起旗⼦。
hero.pickUpFlag(flag)
else:
# ⾃动移动到你能看见的最近的物品。
item = hero.findNearestItem()
if item:
position = item.pos
x = position.x
y = position.y

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。