Codecombat Forest level Python code

Source: Internet
Author: User
Tags chop

Dungeon level is over, next to the edge of the forest!

1, Forest defense

hero.moveup () HERO.BUILDXY("fence", Max.) Hero.movedown () Hero.movedown () HERO.BUILDXY ("fence", 40, 20)

2, Trail

# It ' s the first point of the path. Hero.movexy (+)#  Move at the next points of the path. Hero.movexy (Notoginseng)#  Build A fence to stop the ogre. Hero.movexy (79,18) hero.movexy (73,61) hero.movexy (79,18)

3, the cubicle in the jungle.

Hero.movexy (19, 33) Enemy=Hero.findnearestenemy ()#The conditional judgment will check if the variable is referenced to a ogreifEnemy:hero.attack (Enemy) Hero.attack (enemy) hero.movexy (49, 51) Enemy=Hero.findnearestenemy ()ifEnemy:#write here to attack enemy commandsHero.attack (Enemy) Hero.attack (enemy)#Pass no special meaning, just to help end conditional judgment, write not write can    PassHero.movexy (58, 14) Enemy=Hero.findnearestenemy ()#use conditional judgment to determine if an enemy existsifEnemy:#if the enemy exists, attack him .Hero.attack (Enemy) Hero.attack (enemy)

4,if-stravaganza

 while True:     = Hero.findnearestenemy ()    #  Use an "if" statement to check if an enemy exists:    if  enemy:         #  Attack the enemy if it exists         hero.attack (Enemy)        Hero.attack (enemy)

5, back to back

 while True:     = Hero.findnearestenemy ()    if  enemy:        #  also or take the initiative ...          Hero.attack (Enemy)         Hero.attack (enemy)    Else:        # or return to your position to defend.         Hero.say ("  I can't see the enemy ")        hero.movexy (+)         Pass

6, the forest-splitting person

Hero.movexy (at all) while True:    = hero.findnearestenemy ()    if Hero.isready ("cleave"):        #  "cleave" drop the enemy!          hero.cleave (enemy)        pass    else:        #  Otherwise (if "cleave" is not ready), use your normal attack         hero.attack (enemy)        Pass

7, confrontation in remote areas

 whileTrue:#use a "if-statement" statement in ' IsReady ' to check for "cleave"    ifHero.isready ("Cleave"):        #Chop Chop! Enemy =Hero.findnearestenemy () hero.cleave (enemy)#or, if Cleave is not ready:    Else:        #say something to scare off the man-eating ogre .Hero.say ("Get the hell out of here !  Knives and swords without eyes! ")    Pass

8, Distance meter

Enemy1 ="Gort"Distance1=Hero.distanceto (enemy1) Hero.say (Distance1) enemy2="Smasher"Distance2=Hero.distanceto (enemy2)#Pass the DISTANCE2 variable as a parameter, passing in the Say () methodHero.say (DISTANCE2)#measure and tell the distance between the remaining enemy and the hero#don't shoot at your friendly!Enemy3 ="Charles"Enemy4="Gorgnub"Distance4=Hero.distanceto (enemy4) Hero.say (Distance4)

9, protecting farmers

 while True:     = Hero.findnearestenemy ()    = Hero.distanceto (enemy)    if distance <:         # if they are too close to the peasants, attack them.         Hero.attack (enemy)        pass    #  Otherwise, stay next to the farmer!     Hero.movexy (40, 37)

10, Crazy Ogre.

#Another treasure box on the ground that lets heroes open! #attack the chest to open it#some ogres don't stand there and get beaten up! #when the ogre is too close to you, you have to learn to protect yourself . whileTrue:enemy=hero.findnearestenemy () distance=Hero.distanceto (Enemy)ifHero.isready ("Cleave"):        #First, use Whirlwind (cleave) regularly when the skill is ready:Hero.cleave (Enemy)Pass    elifDistance < 5:        #attack the ogre who is near and closest to you.Hero.attack (Enemy)Pass    Else:        #Otherwise, try breaking the treasure chest to see:Hero.attack ("Chest")        Pass

11, leap fire in the forest

#in this, don't touch the demon stone! Move in other directions and avoid them!  whileTrue:evilstone=Hero.findnearestitem ()ifEvilstone:pos=Evilstone.posifPos.x = = 34:            #If the demon Stone is on the left, go to the right. Hero.movexy (46, 22)            Pass        Else:            #If the demon Stone is on the right, go to the left. Hero.movexy (34, 22)            Pass    Else:        #If there ' s no evilstone, go to the middle.Hero.movexy (40, 22)        Pass

12,

Optional Level 1: Arena

# defeat the enemy heroes in a duel!   while True:    #  finds and attacks enemies in a loop    #  When you're done, submit to the multi-day ladder system!     enemy = hero.findnearestenemy ()    hero.attack (enemy)    if len ( Hero.findnearestenemy ()) > 5:        Hero.shield ()    Else:        hero.attack (enemy )

Codecombat Forest level Python code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.