zoukankan      html  css  js  c++  java
  • 【网易官方】极客战记(codecombat)攻略-森林-盐碱地salted-earth

    保卫森林定居点开始。

    简介

    这个关卡引入了布尔 “or” 的概念。

    在两个布尔值之间放置一个 or 将返回一个布尔值,就像 + 需要 2 个数字并且吐出另一个数字一样。

    如果前或后的值为 true,则返回 true; 如果两者都为 false,则返回 false。

    # 布尔或写作'or'
    hero.say(False or False) # 英雄说'False'
    hero.say(False or True) # 英雄说'True'
    hero.say(True or False) # 英雄说'True'
    hero.say(True or True) # 英雄说'True'

    默认代码

    敬请期待!

    概览

    这个关卡引入了 boolean or 的概念。在两个布尔值之间放置一个 or 将返回一个布尔值,就像 + 需要 2 个数字并且吐出另一个数字(在这种情况下为总和)。

    请记住,布尔值是单个数据,“真” 或 “假”。如果前或后的值为 true,则返回 true; 如果两者都为 false,则返回false。

    # 布尔或写作'or'
    hero.say(False or False) # 英雄说'False'
    hero.say(False or True) # 英雄说'True'
    hero.say(True or False) # 英雄说'True'
    hero.say(True or True) # 英雄说'True'

    如果您知道确切的布尔值,那么这很有用,但编程可以让您做更多!

    回想一下 , , <= , > = , == 返回布尔值,所以使它更有用:

    enemy = hero.findNearestEnemy()
    # 大声读出来会有帮助:
    if hero.distanceTo(enemy) < 10 or enemy.type == "thrower":
        # 如果敌人距离小于10,或,敌人类型是投矛手
    hero.attack(enemy)

    盐碱地 解法

    while True:
        enemy = hero.findNearestEnemy()
        if enemy.type == "munchkin" or enemy.type == "thrower":
            hero.attack(enemy)
        item = hero.findNearestItem()
        if item.type == "coin" or item.type == "gem":
            hero.moveXY(item.pos.x, item.pos.y)
    本攻略发于极客战记官方教学栏目,原文地址为:
  • 相关阅读:
    Entity Framework Core tools reference
    安装 SQL Server 并在 Ubuntu 上创建数据库
    Install Docker Engine on Ubuntu
    ubuntu 18.04 安装.net 5
    C# 远程服务器 安装、卸载 Windows 服务,读取远程注册表,关闭杀掉远程进程
    ASP.NET MVC ActionResult
    使用WCF实现消息推送
    postgresql 数据类型转换,日期操作函数
    sql 按姓氏笔画(拼音)排序
    postgresql 导入导出
  • 原文地址:https://www.cnblogs.com/codecombat/p/12375835.html
Copyright © 2011-2022 走看看