• 「网易官方」极客战记(codecombat)攻略-游戏开发2-牢笼-cages


                                                                              (点击图片进入关卡)

    栅栏不会保护食人魔免受游戏大师的怒气。

    简介

    unit.destroy() 从游戏中移除一个单位,就像没有生成过。

    unit.defeat() 将单位留在游戏中,但他是 “defeated”。

    在这个关卡,计算生成的 munchins 和 scouts。当产生足够的量时,对栅栏使用 destroy (摧毁)并 defeat (击败)生成器。 对栅栏使用 destroy (摧毁)并 defeat (击败)生成器。

    if game.scoutsSpawned >= 5:
    someGenerator.defeat()
    someWall.destroy()

    默认代码

    # 了解摧毁与击败的区别。
    # 生成敌人
    ogre1 = game.spawnXY("ogre", 12, 18)
    ogre1.behavior = "AttacksNearest"
    ogre2 = game.spawnXY("ogre", 68, 50)
    ogre2.behavior = "AttacksNearest"
    munchkinGenerator = game.spawnXY("generator", 12, 50)
    munchkinGenerator.spawnAI = "Scampers"
    munchkinGenerator.spawnType = "munchkin"
    scoutGenerator = game.spawnXY("generator", 68, 12)
    scoutGenerator.spawnAI = "Scampers"
    scoutGenerator.spawnType = "scout"
    # 我们将在之后摧毁的栅栏。
    leftFence = game.spawnXY("fence", 26, 14)
    rightFence = game.spawnXY("fence", 54 , 50)
    player = game.spawnPlayerXY("knight", 40, 34)
    player.maxSpeed = 16
    player.attackDamage = 20
    # 游戏目标计数器
    game.scoutsSpawned = 0
    game.munchkinsSpawned = 0
    game.bossesDefeated = 0
    ui.track(game, "scoutsSpawned")
    ui.track(game, "munchkinsSpawned")
    ui.track(game, "bossesDefeated")
    bossesGoal = game.addManualGoal("击败两个大食人魔。")
    def onSpawn(event):
        unit = event.target
        if unit.type == "scout":
            game.scoutsSpawned += 1
        if game.scoutsSpawned >= 3:
            # 使用defeat() 方法击败scoutGenerator(战士生成器)
            # 使用destroy() 方法摧毁 rightFence(右边的栅栏)。
            pass
        if unit.type == "munchkin":
            game.munchkinsSpawned += 1
        if game.munchkinsSpawned >= 2:
            # 击败munchkinGenerator(兽人生成器)。
            # 摧毁 leftFence(左边的栅栏)
            pass
    def onDefeat(event):
        unit = event.target
        if unit.type == "ogre":
            # 往 the game.bossesDefeated加一
            game.bossesDefeated += 1
    game.setActionFor("munchkin", "spawn", onSpawn)
    game.setActionFor("scout", "spawn", onSpawn)
    game.setActionFor("ogre", "defeat", onDefeat)
    while True:
        if game.bossesDefeated >= 2:
            game.setGoalState(bossesGoal, True)

    概览

    敬请期待!

    牢笼 解法

    # 了解摧毁与击败的区别。
    # 生成敌人
    ogre1 = game.spawnXY("ogre", 12, 18)
    ogre1.behavior = "AttacksNearest"
    ogre2 = game.spawnXY("ogre", 68, 50)
    ogre2.behavior = "AttacksNearest"
    munchkinGenerator = game.spawnXY("generator", 12, 50)
    munchkinGenerator.spawnAI = "Scampers"
    munchkinGenerator.spawnType = "munchkin"
    scoutGenerator = game.spawnXY("generator", 68, 12)
    scoutGenerator.spawnAI = "Scampers"
    scoutGenerator.spawnType = "scout"
    # 我们将在之后摧毁的栅栏。
    leftFence = game.spawnXY("fence", 26, 14)
    rightFence = game.spawnXY("fence", 54 , 50)
    player = game.spawnPlayerXY("knight", 40, 34)
    player.maxSpeed = 16
    player.attackDamage = 20
    # 游戏目标计数器
    game.scoutsSpawned = 0
    game.munchkinsSpawned = 0
    game.bossesDefeated = 0
    ui.track(game, "scoutsSpawned")
    ui.track(game, "munchkinsSpawned")
    ui.track(game, "bossesDefeated")
    bossesGoal = game.addManualGoal("击败两个大食人魔。")
    def onSpawn(event):
        unit = event.target
        if unit.type == "scout":
            game.scoutsSpawned += 1
        if game.scoutsSpawned >= 3:
            # 使用defeat() 方法击败scoutGenerator(战士生成器)
            scoutGenerator.defeat()
            # 使用destroy() 方法摧毁 rightFence(右边的栅栏)。
            rightFence.destroy()
            pass
        if unit.type == "munchkin":
            game.munchkinsSpawned += 1
        if game.munchkinsSpawned >= 2:
            # 击败munchkinGenerator(兽人生成器)。
            munchkinGenerator.defeat()
            # 摧毁 leftFence(左边的栅栏)
            leftFence.destroy()
    def onDefeat(event):
        unit = event.target
        if unit.type == "ogre":
            # 往 the game.bossesDefeated加一
            game.bossesDefeated += 1
    game.setActionFor("munchkin", "spawn", onSpawn)
    game.setActionFor("scout", "spawn", onSpawn)
    game.setActionFor("ogre", "defeat", onDefeat)
    while True:
        if game.bossesDefeated >= 2:
            game.setGoalState(bossesGoal, True)
     
     

    本攻略发于极客战记官方教学栏目,原文地址为:

    https://codecombat.163.com/news/jikezhanji-laolong

    极客战记——学编程,用玩的!

  • 相关阅读:
    lua学习笔记
    s2-029 Struts2 标签远程代码执行分析(含POC)
    GoAccess日志分析工具使用文档
    error: command 'gcc' failed with exit status 1 的解决办法
    机器学习算法总结(八)——广义线性模型(线性回归,逻辑回归)
    机器学习中常见的过拟合解决方法
    机器学习算法总结(七)——隐马尔科夫模型(前向后向算法、鲍姆-韦尔奇算法、维特比算法)
    机器学习算法总结(六)——EM算法与高斯混合模型
    机器学习中常见的损失函数
    机器学习算法总结(五)——聚类算法(K-means,密度聚类,层次聚类)
  • 原文地址:https://www.cnblogs.com/codecombat/p/12794361.html
Copyright © 2020-2023  润新知