[Official] Netease Wars geeks (codecombat) Raiders - Forest - Picnic Destroyer

Level connection: https://codecombat.163.com/play/level/picnic-buster

Free Trial: https://codecombat.163.com/play

Protection picnickers from the hands of the ogres patrol.

Brief introduction

Use an if statement to protect people camping, came when the ogre attack.

The if statement is crucial for programmers, they look like this:

enemy = hero.findNearestEnemy()
if enemy:
    hero.attack(enemy)

The default code

# Remember that the enemy may not exist.
while True:
    enemy = hero.findNearestEnemy()
    if enemy:
    # If there is an enemy, attack it!

Overview

With "patrol killer" as in, you have to attack the nearest enemy, but only in the presence of the enemy when attacking. Use an if statement, followed by the enemy to be evaluated.

enemy = hero.findNearestEnemy()
if enemy:
    hero.attack(enemy)

Remember the mouse over the lower right corner of if / else read syntax example.

Picnic Destroyer solution

    # Remember that the enemy may not exist.
while True:
    enemy = hero.findNearestEnemy()
     # If there is an enemy, attack it!
    if enemy:
        hero.attack(enemy)
 
 
Raiders made in the official teaching Wars geeks column, the original address is:

Guess you like

Origin www.cnblogs.com/codecombat/p/12165059.html