「网易官方」极客战记(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

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

猜你喜欢

转载自www.cnblogs.com/codecombat/p/12794361.html