zoukankan      html  css  js  c++  java
  • 【网易官方】极客战记(codecombat)攻略-森林-冰冻打击hit-and-freeze

    一个被困的肉食动物,仍然是一个危险的肉食动物

    简介

    你陷入了陷阱! 等到食人魔近身,然后攻击,否则你会伤害自己!

    函数可以返回一个值,包括一个 boolean 值(true 或 false)。

    用这个来决定是否一个食人魔是 inattackrange() !

    def inAttackRange(enemy):
        distance = hero.distanceTo(enemy)
        if distance <= 3:
            # return True because the enemy is in range
        else:
            # return False because the enemy is out of range

    将结果保存到一个变量中,稍后在代码中使用它:

    canAttack = inAttackRange(target)

    默认代码

    # 你掉进陷阱里了!别动!你会受伤的!
    # 这个函数检查敌人是否再攻击范围。
    def inAttackRange(enemy):
        distance = hero.distanceTo(enemy)
        # 几乎所有的剑都有3的攻击范围。
        if distance <= 3:
            return True
        else:
            return False
    # 只有在触手可及的范围内才能攻击食人魔。
    while True:
        # 找到最近的敌人,并将其储存在一个变量中。

     

        # 调用 inAttackRange(enemy),将 enemy 作为参数
        # 把结果保存于 “canAttack” 变量中

     

        # 如果结果存储在一个攻击中 True, 然后下手!

     

        pass

    概览

    你可以在一个函数中使用多个 return 语句,但是只有一个会被使用,因为 return 会导致函数停止执行,并且返回回函数被调用的地方。

    def moreThanTen(n):
        # 如果'n'大于10,则函数返回true
        if n > 10:
            return True
        # 否则'else'内的'return'就会被调用,函数会返回false
        else:
            return False

     

    isSmall = moreThanTen(5) # isSmall == true

    冰冻打击 解法

    # 你掉进陷阱里了!别动!你会受伤的!
    # 这个函数检查敌人是否再攻击范围。
    def inAttackRange(enemy):
        distance = hero.distanceTo(enemy)
        # 几乎所有的剑都有3的攻击范围。
        if distance <= 3:
            return True
        else:
            return False
    # 只有在触手可及的范围内才能攻击食人魔。
    while True:
        # 找到最近的敌人,并将其储存在一个变量中。
        nearestEnemy = hero.findNearestEnemy()

     

        # 调用 inAttackRange(enemy),将 enemy 作为参数
        # 把结果保存于 “canAttack” 变量中
        canAttack = inAttackRange(nearestEnemy)

     

        # 如果结果存储在一个攻击中 True, 然后下手!
        if canAttack:
            hero.attack(nearestEnemy)
     
     
     
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    形象理解ERP(转)
    禁用windows server 2008 域密码复杂性要求策略
    How to adding find,filter,remove filter on display method Form
    Windows Server 2008 R2激活工具
    How to using bat command running VS development SSRS report
    Creating Your First Mac AppGetting Started
    Creating Your First Mac AppAdding a Track Object 添加一个 Track 对象
    Creating Your First Mac AppImplementing Action Methods 实现动作方法
    Creating Your First Mac AppReviewing the Code 审查代码
    Creating Your First Mac AppConfiguring the window 设置窗口
  • 原文地址:https://www.cnblogs.com/codecombat/p/12342146.html
Copyright © 2011-2022 走看看