code combat -- SLALON
继续打code combat, 这一局是用判断句来决定英雄是躲避兽夹还是收集宝石。。
程序本来要求一步一步的手动输入数值。我做了一个小小的改动,用变量i 来计算出每一次的了数值。。。简化了一点点操做
源代码
# Use object literals to walk the safe path and collect the gems.
# You cannot use moveXY() on this level! Use move() to get around.
gems = hero.findItems()
while hero.pos.x < 20:
# move() takes objects with x and y properties, not just numbers.
hero.move({'x': 20, 'y': 35})
while hero.pos.x < 25:
# A gem's position is an object with x and y properties.
gem0 = gems[0]
hero.move(gem0.pos)
# While your x is less than 30,
# Use an object to move to 30, 35.
i = 1
while hero.pos.x < 5 * (i + 5):
hero.move({'x': 5 * (i + 5), 'y': 35})
while hero.pos.x < 5 * (i + 6):
gem = gems[i]
hero.move(gem.pos)
i += 2
while hero.pos.x < 5 * (i + 5):
hero.move({'x': 5 * (i + 5), 'y': 35})
while hero.pos.x < 5 * (i + 6):
gem = gems[(i + 1)/2]
hero.move(gem.pos)
i += 2
while hero.pos.x < 5 * (i + 5):
hero.move({'x': 5 * (i + 5), 'y': 35})
while hero.pos.x < 5 * (i + 6):
gem = gems[(i + 1)/2]
hero.move(gem.pos)
i += 2
while hero.pos.x < 5 * (i + 5):
hero.move({'x': 5 * (i + 5), 'y': 35})
while hero.pos.x < 5 * (i + 6):
gem = gems[(i + 1)/2]
hero.move(gem.pos)
# While your x is less than 35,
# Move to the position of gems[1].
# Get to the last couple of gems yourself!
给铁柱拍手👏
看到铁柱玩得那么兴起 - 我也跑去完了下,确实蛮好玩的 XD
大力拍拍!