你可以使用行为属性来改变单位的 AI。
简介
单位的行为可以通过 behavior 属性来设置。
skeleton3.behavior = "Scampers" 这句代码会让 skeleton3 变量中存储的骷髅怪随机移动。
skeleton3.behavior = "AttacksNearest" 则是攻击最近的敌人。
skeleton3.behavior = "Defends" 则只在敌人接近时发起攻击。
skeleton3.behavior = "RunsAway" 会让单位从玩家周围逃开。
记得选取正确的变量,如 skeleton3 、 ogre2 、 ogre3 、 archer1 !
默认代码
# 使用behavior属性为单位指定行为。
skeleton1 = game.spawnXY("skeleton", 60, 48)
skeleton2 = game.spawnXY("skeleton", 60, 30)
skeleton3 = game.spawnXY("skeleton", 60, 12)
skeleton1.behavior = "Scampers"
skeleton2.behavior = "Scampers"
# 将"Scampers"指定给 skeleton3.behavior
ogre1 = game.spawnXY("ogre", 70, 50)
ogre2 = game.spawnXY("ogre", 70, 30)
ogre3 = game.spawnXY("ogre", 70, 10)
ogre1.behavior = "AttacksNearest"
# 将"AttacksNearest"指定给 ogre2.behavior
# 将"AttacksNearest"指定给 ogre3.behavior
archer1 = game.spawnXY("archer", 10, 30)
# 将"Defends"指定给 archer1.behavior
# 下面这里不要做任何修改。
# 不过不妨看看!
player = game.spawnPlayerXY("raider", 20, 30)
player.attackDamage = 10
player.maxHealth = 9001
game.addSurviveGoal()
game.addDefeatGoal()
game.spawnXY("forest", 40, 10)
game.spawnXY("forest", 40, 18)
game.spawnXY("forest", 40, 26)
game.spawnXY("forest", 40, 42)
game.spawnXY("forest", 40, 50)
game.spawnXY("forest", 40, 58)
game.spawnXY("lightstone", 30, 45)
game.spawnXY("lightstone", 30, 20)
game.spawnXY("lightstone", 30, 55)
game.spawnXY("lightstone", 30, 10)
game.spawnXY("potion-medium", 10, 50)
game.spawnXY("potion-medium", 10, 15)
概览
Coming soon!
行为驱动开发 解法
# 使用behavior属性为单位指定行为。
skeleton1 = game.spawnXY("skeleton", 60, 48)
skeleton2 = game.spawnXY("skeleton", 60, 30)
skeleton3 = game.spawnXY("skeleton", 60, 12)
skeleton1.behavior = "Scampers"
skeleton2.behavior = "Scampers"
# 将"Scampers"指定给 skeleton3.behavior
skeleton3.behavior = "Scampers"
ogre1 = game.spawnXY("ogre", 70, 50)
ogre2 = game.spawnXY("ogre", 70, 30)
ogre3 = game.spawnXY("ogre", 70, 10)
ogre1.behavior = "AttacksNearest"
# 将"AttacksNearest"指定给 ogre2.behavior
ogre2.behavior = "AttacksNearest"
# 将"AttacksNearest"指定给 ogre3.behavior
ogre3.behavior = "AttacksNearest"
archer1 = game.spawnXY("archer", 14, 30)
# 将"Defends"指定给 archer1.behavior
archer1.behavior = "Defends"
# 下面这里不要做任何修改
# 不过不妨看看!
player = game.spawnPlayerXY("raider", 20, 30)
player.attackDamage = 10
player.maxHealth = 9001
game.addSurviveGoal()
game.addDefeatGoal()
game.spawnXY("forest", 40, 10)
game.spawnXY("forest", 40, 18)
game.spawnXY("forest", 40, 26)
game.spawnXY("forest", 40, 42)
game.spawnXY("forest", 40, 50)
game.spawnXY("forest", 40, 58)
game.spawnXY("lightstone", 30, 45)
game.spawnXY("lightstone", 30, 20)
game.spawnXY("lightstone", 30, 55)
game.spawnXY("lightstone", 30, 10)
game.spawnXY("potion-medium", 10, 50)
game.spawnXY("potion-medium", 10, 15)
本攻略发于极客战记官方教学栏目,原文地址为:
https://codecombat.163.com/news/jikezhanji-xingweiqudongkaifa
来源:oschina
链接:https://my.oschina.net/u/4441837/blog/3189188