极客战记-盲距
如果你卡在这里了,那么看看这个攻略吧
准备工作
1、选择英雄和编程语言
2、选择装备
3、写中文注释
python
1、写代码#你的任务是告飙攴涡芩诉他兽人的距离。#这个函数寻找最近的敌人,并返回距离。#Ifthereisnoenemy,thefunctionreturns0.defnearestEnemyDistance():enemy=hero.findNearestEnemy()result=0ifenemy:result=hero.distanceTo(enemy)returnresultwhileTrue:#CallnearestEnemyDistance()and#savetheresultinthevariableenemyDistance.enemyDistance=nearestEnemyDistance()#IftheenemyDistanceisgreaterthan0:ifenemyDistance>0:#SaythevalueofenemyDistancevariable.hero.say(enemyDistance)
2、运行
javascript
1、写代码// 你的任务是告诉他兽人的距离。// 这个函数寻找最近的敌人,并返回距离。// If there is no enemy, the function returns 0.functio荏鱿胫协n nearestEnemyDistance() { var enemy = hero.findNearestEnemy(); var result = 0; if (enemy){ result = hero.distanceTo(enemy);} return result;}while(true) { // Call nearestEnemyDistance() and // save the result in the variable enemyDistance. var enemyDistance = nearestEnemyDistance(); // If the enemyDistance is greater than 0: if (enemyDistance>0){ // Say the value of enemyDistance variable. hero.say(enemyDistance);}}
2、运行
coffeescript
1、写代码# 这个函数寻找最近的敌人,并返回距离。@nearestEnemyDistance = -> enemy = hero.findNearestEnemy() result = 0 if enemy result = hero.distanceTo(enemy) return resultwhile true enemyDistance = @nearestEnemyDistance() if enemyDistance>0 hero.say(enemyDistance)
2、运行
lua
1、写代码local function nearestEnemyDistance() local enemy = hero:findNearestEnemy() local result = 0 if enemy then local result = hero:distanceTo(enemy) end return resultendwhile true do local enemyDistance = nearestEnemyDistance() if enemyDistance>0 then hero:say(enemyDistance) endend
2、运行