【网易官方】极客战记(codecombat)攻略-森林-濒危树林之战endangered-burl
在叢林中獵殺食人魔, 注意不要驚動其他野獸
簡介
通過檢查他們的'類型'了解關于你的敵人更多東西。
enemy = hero.findNearestEnemy()
if enemy.type is "munchkin":
hero.attack(enemy)
請注意, type 不像'moveXY(20,20) 那樣是**方法**。 在 type 之后不要包含 ()`。
默認代碼
# 只攻擊幼小食人魔和投擲者食人魔。
# 別攻擊樹榴,遇到食人魔快跑。
while True:
enemy = hero.findNearestEnemy()
# 記住:別攻擊樹精『burl』
if enemy.type == "burl":
hero.say("我不攻擊樹榴『burl』")
# type 屬性告訴你它是什么種類的生物
if enemy.type == "munchkin":
hero.attack(enemy)
# 使用『if』來攻擊投擲者『thrower』
# 如果它是一個食人魔『ogre』,跑到村口去!
概覽
每個敵人都有一個名為 type 的屬性,它是一個字符串(引號中的一段數(shù)據(jù),比如 “thrower”)。
使用 if-statements 來檢查敵人的 “類型” 可以讓你選擇不同的敵人!
在這個關卡中,你想'攻擊''thrower'和'munchkin' 類型的敵人。 你應該忽略 type burl`的敵人, 并逃離`類型`食人魔的敵人。
你可以像這樣檢查敵人的'類型':
enemy = hero.findNearestEnemy()
if enemy.type is "munchkin":
hero.attack(enemy)
請注意, type 是一個屬性,而不是像 moveXY(20,20) 這樣的方法。在 type 之后不要包含 () 。
注意 if 語句的語法正確!將鼠標懸停在右下角的 “if / else” 上查看示例。
瀕危樹林之戰(zhàn) 解法
# 只攻擊幼小食人魔和投擲者食人魔。
# 別攻擊樹榴,遇到食人魔快跑。
while True:
enemy = hero.findNearestEnemy()
# 記住:別攻擊樹精『burl』
if enemy.type == "burl":
hero.say("I'm not attacking that Burl!")
# type 屬性告訴你它是什么種類的生物
if enemy.type == "munchkin":
hero.attack(enemy)
# 使用『if』來攻擊投擲者『thrower』
if enemy.type == "thrower":
hero.attack(enemy)
# 如果它是一個食人魔『ogre』,跑到村口去!
if enemy.type == "ogre":
hero.moveXY(41, 47)
本攻略發(fā)于極客戰(zhàn)記官方教學欄目,原文地址為:
https://codecombat.163.com/news/jikezhanji-bingweishulinzhizhan
極客戰(zhàn)記——學編程,用玩的!
總結
以上是生活随笔為你收集整理的【网易官方】极客战记(codecombat)攻略-森林-濒危树林之战endangered-burl的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。