其他分享
首页 > 其他分享> > 「网易官方」极客战记(codecombat)攻略-游戏开发2-切换目标-stick-shift

「网易官方」极客战记(codecombat)攻略-游戏开发2-切换目标-stick-shift

作者:互联网

                                                                         (点击图片进入关卡)

了解如何为您的游戏创建自定义目标!

简介

现在您可以为您的游戏创建自定义目标!

我们将它们称为手动目标,因为您负责将它们手动标记为成功或失败。 像这样创建一个手动目标:

myGoal = game.addManualGoal("击败骷髅,救下射手!") def onDefeat(event):     unit = event.target     if unit.type == "skeleton":         game.setGoalState(myGoal, True)     if unit.type == "archer":         game.setGoalState(myGoal, False) game.setActionFor("archer", "defeat", onDefeat) game.setActionFor("skeleton", "defeat", onDefeat)

默认代码

# 现在你可以为你的游戏创建一个自定义目标 # 使用 game.addManualGoal(描述)方法! # 构建一些侦察员,老板和迷宫。 game.spawnMaze(5) game.spawnXY("scout", 60, 58) game.spawnXY("scout", 28, 29) game.spawnXY("scout", 61, 24) ogref = game.spawnXY("ogre-f", 60, 12) # 构建并配置英雄。 hero = game.spawnPlayerXY("captain", 12, 56) hero.maxHealth = 550 hero.maxSpeed = 10 hero.attackDamage = 25 # 构建一个兽人生成器。 generator = game.spawnXY("generator", 41, 13) generator.spawnDelay = 5 generator.spawnType = "munchkin" # 存活目标。 game.addSurviveGoal() game.spawnXY("potion-medium", 28, 12) # addManualGoal添加一个描述不完整的目标 # 描述将显示给玩家。 # 注意要将其保存在名为scoutGoal的变量中 scoutGoal = game.addManualGoal("Defeat all scouts") # 使用addManualGoal添加一个目标来击败Boss # 将其保存在名为bossGoal的变量中 # 敌人的行为 def onSpawn(event):     unit = event.target     while True:         enemy = unit.findNearestEnemy()         if enemy:             unit.attack(enemy) game.setActionFor("scout", "spawn", onSpawn) game.setActionFor("ogre", "spawn", onSpawn) # 计算有多少侦察兵被打败.. scoutsDefeated = 0 # 每当敌人失败时更新我们的自定义目标。 # 这是一个使用if语句的算法的例子。 def onDefeat(event):     unit = event.target     if unit.type == "scout":         scoutsDefeated += 1         hero.say("Scout down!")     if scoutsDefeated >= 3:         # 使用setGoalState标记达成的侦察目标。         game.setGoalState(scoutGoal, True)         hero.say("All Scouts down!")     if unit.type == "ogre":         # 使用game.setGoalState标记boss目标达到。         # 不要忘记第二个参数。

 

        hero.say("Defeated the big boss!") # 将失败处理程序分配给食人魔"defeat" # 注意兽人是不会成功的! game.setActionFor("scout", "defeat", onDefeat) game.setActionFor("ogre", "defeat", onDefeat)

概览

敬请期待!

切换目标 解法

# 现在你可以为你的游戏创建一个自定义目标 # 使用 game.addManualGoal(描述)方法! # 构建一些侦察员,老板和迷宫。 game.spawnMaze(5) game.spawnXY("scout", 60, 58) game.spawnXY("scout", 28, 29) game.spawnXY("scout", 61, 24) ogref = game.spawnXY("ogre-f", 60, 12) # 构建并配置英雄。 hero = game.spawnPlayerXY("captain", 12, 56) hero.maxHealth = 550 hero.maxSpeed = 10 hero.attackDamage = 25 # 构建一个兽人生成器。 generator = game.spawnXY("generator", 41, 13) generator.spawnDelay = 5 generator.spawnType = "munchkin" # 存活目标。 game.addSurviveGoal() game.spawnXY("potion-medium", 28, 12) # addManualGoal添加一个描述不完整的目标 # 描述将显示给玩家。 # 注意要将其保存在名为scoutGoal的变量中 scoutGoal = game.addManualGoal("Defeat all scouts") # 使用addManualGoal添加一个目标来击败Boss # 将其保存在名为bossGoal的变量中 bossGoal = game.addManualGoal("Defeat the big boss!") # 敌人的行为 def onSpawn(event):     unit = event.target     while True:         enemy = unit.findNearestEnemy()         if enemy:             unit.attack(enemy) game.setActionFor("scout", "spawn", onSpawn) game.setActionFor("ogre", "spawn", onSpawn) # 计算有多少侦察兵被打败.. scoutsDefeated = 0 # 每当敌人失败时更新我们的自定义目标。 # 这是一个使用if语句的算法的例子。 def onDefeat(event):     unit = event.target     if unit.type == "scout":         scoutsDefeated += 1         hero.say("Scout down!")     if scoutsDefeated >= 3:         # 使用setGoalState标记达成的侦察目标。         game.setGoalState(scoutGoal, True)         hero.say("All Scouts down!")     if unit.type == "ogre":         # 使用game.setGoalState标记boss目标达到。         # 不要忘记第二个参数。         game.setGoalState(bossGoal, True)         hero.say("Defeated the big boss!")         hero.say("Defeated the big boss!") # 将失败处理程序分配给食人魔"defeat" # 注意兽人是不会成功的! game.setActionFor("scout", "defeat", onDefeat) game.setActionFor("ogre", "defeat", onDefeat)    

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

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

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

标签:codecombat,极客,hero,game,scout,战记,spawnXY,event,unit
来源: https://www.cnblogs.com/codecombat/p/12777353.html