「网易官方」极客战记(codecombat)攻略-山峰-联合做战-mixed-unit-tactics

找出最佳的兵种组合, 击退食人大队
简介
开放式防御水平!
依靠你的技能生存 30 秒并收集 300 金币。
你能把它变成 60 秒吗?
默认代码
# 练习用取模从数组中循环取值 # 在数组array中编排好兵种组合 summonTypes = [] def summonTroops(): # 用%取模来循环预设的征兵方案 len(self.built) #type = summonTypes[???] hero.say("I should summon troops!")概览
首先,按照您要召唤的单位类型填写 “summonTypes” 数组。
然后,使用 summonTroops 函数完成
len(hero.built) % len(summonTypes)遍历 summonTypes 数组。
您还需要创建一个 collectCoins 函数和一个 commandTroops 函数。
提示:在 commandTroops 中,您会想要跳过任何拥有 type =="palisade" 的朋友!
联合做战解法
# 练习用取模从数组中循环取值 # 在数组array中编排好兵种组合 summonTypes = [] def summonTroops(): # 用%取模来循环预设的征兵方案 len(self.built) type = summonTypes[len(hero.built) % len(summonTypes)] if(hero.costOf(type) <= hero.gold): hero.summon(type)def gatherCoins(): items = hero.findItems() item = hero.findNearest(items) if item: hero.move(item.pos) def commandTroops(): friends = hero.findFriends() for i in range(len(friends)): friend = friends[i] enemy = friend.findNearestEnemy() if enemy: hero.command(friend, "attack", enemy) while True: summonTroops() gatherCoins() commandTroops()
本攻略发于极客战记官方教学栏目,原文地址为:
https://codecombat.163.com/news/jikezhanji-lianhezuozhan
极客战记——学编程,用玩的