「网易官方」极客战记(codecombat)攻略-沙漠-捡闪亮东西的人-shine-getter

(点击图片进入关卡)

过滤所有的硬币,在短时间内得到最多的金币

简介

用'while'循环查找具有 findItems() 的硬币数组。

coins = hero.findItems()
coinIndex = 0
while coinIndex < len(coins):
    coin = coins[coinIndex]
    hero.moveXY(coin.pos.x, coin.pos.y)
    coinIndex += 1

默认代码

# 很快的获取最多的金币
while True:
    coins = hero.findItems()
    coinIndex = 0

 

    # 把这个封装进循环里枚举所有的硬币

 

    coin = coins[coinIndex]
    # 金币价值3点。
    if coin.value == 3:
        # 只捡金币。

 

        pass

概览

这次你会用上 while 循环遍历物品而不是敌人,目的也换成了找到金币。

就像在示例代码里那样,每个硬币的 value 属性可以判断硬币的类型。

金币的 value 为 3 。

使用 moveXY 只移动到金币的 pos.x 和 pos.y 。

捡闪亮东西的人解法

# 很快的获取最多的金币
while True:
    coins = hero.findItems()
    coinIndex = 0

 

    # 把这个封装进循环里枚举所有的硬币
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        # 金币价值3点。
        if coin.value == 3:
            # 只捡金币。
            hero.moveXY(coin.pos.x, coin.pos.y)
        coinIndex += 1
 
本攻略发于极客战记官方教学栏目,原文地址为:
原文地址:https://www.cnblogs.com/codecombat/p/13424649.html