# 使用对象枚举来走安全的路,并收集宝石。
# 在本关你不能够使用 moveXY()方法!使用 move()来移动
gems = hero.findItems()
while hero.pos.x < 20:
# move()移动物体通过 x 和 y 的属性,不仅仅是数字。
hero.move({'x': 20, 'y': 35})
while hero.pos.x < 25:
# 一个宝石的位置是一个对象,有 x 和 y 属性。
gem0 = gems[0]
hero.move(gem0.pos)
# 当你的 x 小于30的时候,
# 使用物体移动到30,35位置
while hero.pos.x < 30:
hero.move({'x': 30, 'y': 35})
# 当你的 x 小于35的时候
# 移动到宝石[1]的位置
while hero.pos.x < 35:
gem1 = gems[1]
hero.move(gem1.pos)
# 拿到最后一对宝石!
while hero.pos.x < 40:
# move()移动物体通过 x 和 y 的属性,不仅仅是数字。
hero.move({'x': 40, 'y': 35})
while hero.pos.x < 45:
# 一个宝石的位置是一个对象,有 x 和 y 属性。
hero.move({'x': 45, 'y': 25})
# 当你的 x 小于30的时候,
# 使用物体移动到30,35位置
while hero.pos.x < 50:
hero.move({'x': 50, 'y': 35})
# 当你的 x 小于35的时候
# 移动到宝石[1]的位置
while hero.pos.x < 55:
hero.move({'x': 55, 'y': 25})
这篇文章描述了一种策略,通过使用对象的x和y属性而不是moveXY()方法来控制英雄移动,依次收集地图上的宝石。首先,英雄被移动到特定坐标,然后按照预设路径和宝石位置进行移动,确保所有宝石被拾取。
193

被折叠的 条评论
为什么被折叠?



