zoukankan      html  css  js  c++  java
  • 【网易官方】极客战记(codecombat)攻略-森林-Burlbole 树林-burlbole-grove

    攻击还是不攻击? 就是那个问题。

    简介

    函数可以 return 一个值!

    当一个函数被调用时,它将等于它 returns 的任何值。

    def plusTwo(x):
        return x + 2
    number = plusTwo(5)
    # 现在数量是7

    默认代码

    # 不要攻击树妖!
    # 函数可以返回一个值。
    # 当函数被调用时,它将等于函数返回的值。
    def shouldAttack(target):
        # return False 如果没有`target`

     

        # return False 如果target.type == "burl

     

        # 除此之外 return True
        return True
    while True:
        enemy = hero.findNearestEnemy()
        # 在这里,我们使用shouldAttack()来决定是否应该进行攻击!
        # heroShouldAttack将被分配与shouldAttack() 返回的值相同的值!
        heroShouldAttack = shouldAttack(enemy)
        if heroShouldAttack:
            hero.attack(enemy)

    概览

    函数可以 return 一个值!

    当一个函数被调用时,它将等于它 returns 的任何值。

    def plusTwo(x):
        return x + 2
    number = plusTwo(5)
    # number is now 7

    在这个级别,如果有一个有效的攻击目标,你的函数 shouldAttack(target) 需要返回 true,否则返回 false。

    然后,你的代码可以使用 shouldAttack 来决定你的英雄是否应该攻击!

    def shouldAttack(target):
        # 如果没有目标,则返回false
        if not target:
            return False
        # 如果target.type =="burl",也返回false
        # 否则,返回true
        return True

    注意:当函数执行 return 语句时,该函数立即结束!

    def foo():
        return "foo"
        hero.say("bar") # 这绝不会发生!

    Burlbole 树林 解法

    # 不要攻击树妖!
    # 函数可以返回一个值。
    # 当函数被调用时,它将等于函数返回的值。
    def shouldAttack(target):
        # return False 如果没有`target`
        if not target:
            return False
        # return False 如果target.type == "burl
        if target.type == "burl":
            return False
        # 除此之外 return True
        return True
    while True:
        enemy = hero.findNearestEnemy()
        # 在这里,我们使用shouldAttack()来决定是否应该进行攻击!
        # heroShouldAttack将被分配与shouldAttack() 返回的值相同的值!
        heroShouldAttack = shouldAttack(enemy)
        if heroShouldAttack:
            hero.attack(enemy)
     
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    Oracle EBS—PL/SQL环境初始化之 fnd_global.apps_initialize
    fnd_profile.value的用法
    FND_MESSAGE 消息提示详解
    FORM触发器执行顺序
    大数据实战精英+架构师班 ④ 期
    .Net Core3.0 WebApi 十五:使用Serilog替换掉Log4j
    .Net Core3.0 WebApi 十四:基于AOP的切面redis缓存
    .Net Core3.0 WebApi 十三:自定义返回Json大小写格式
    .Net Core3.0 WebApi 十二:自定义全局消息返回过滤中间件
    .Net Core3.0 WebApi 十一:基于Log4j的全局异常处理
  • 原文地址:https://www.cnblogs.com/codecombat/p/12334335.html
Copyright © 2011-2022 走看看