![](/uploads/1/2/5/7/125750314/910463689.jpeg)
Download assets. Developer: CodeCombat Inc; Based in San Francisco, California. David Chase - [email protected].
CodeCombat is a multiplayer programming game for learning how to code. It’s a platform for students to learn computer science while playing through a real game.It’s both a startup and a community project, completely open source under the MIT and Creative Commons licenses. Furthermore, it’s the largest open source CoffeeScript project by lines of code, and since it’s a game, it’s really fun to hack on.To install CodeCombat, we need to first setup our database.
# The commands below an if statement only run when the if's condition is true. # Fix all the if-statements to beat the level. If 1 + 1 + 1 is 4 # ∆ Make this false.
@ moveXY 5, 15 # Move to the first mines. If 2 + 2 is 4 # ∆ Make this true.
@ moveXY 15, 40 # Move to the first gem. If 2 + 2 isnt 5 # ∆ Make this true. @ moveXY 25, 15 # Move to the second gem. # You can put one if-statement within another if-statement.
# However, doing so can be tricky, so you have to pay close attention to how the if statements interact with each other. # Make sure the indentation is correct!
# Use comments to describe your logic in plain language! # It's helpful to start with one outer if/else, using comments as placeholders for the inner if/else, like so: loop enemy = @ findNearestEnemy# If there is an enemy, then. If enemy# Create a distance variable with distanceTo. Distance = @ distanceTo(enemy)# If the enemy is less than 5 meters away, then attack if distance. # Use 'if' and 'else if' to handle any situation. # Put it all together to defeat enemies and pick up coins! # Make sure you bought great armor from the item shop!
400 health recommended. Loop # @say 'Delete this when your loop isn't infinite.' Flag = @ findFlagenemy = @ findNearestEnemyitem = @ findNearestItemif flag# What happens when I find a flag? @ pickUpFlag flagelse if enemy# What happens when I find an enemy?
If @ distanceTo(enemy). Def moveTo( position, fast = True):if( self. IsReady( 'jump') and fast):self. JumpTo( position)else:self.
Move( position)summonTypes = 'paladin'def summonTroops:type = summonTypes len( self. Built)% len( summonTypes)if self. CostOf( type):self.
Summon( type)def commandPaladin( paladin):enemy = paladin. FindNearest( self. FindEnemies)if( paladin.
CanCast ( 'heal')):target = Noneif( self. Health 40):# self.buildXY('caltrops', self.pos.x, self.pos.y)#elif self.canCast('chain-lightning', target):if self. CanCast( 'chain-lightning', target) and self. DistanceTo( target) 10:moveTo( target. Pos)elif self. IsReady( 'bash'):self. Bash( enemy)else:self.
Attack( target)loop:summonTroopscommandTroopsenemy = self. FindNearest( self.
FindEnemies)#thrower = self.findNearest(self.findByType('thrower'))#if thrower:# enemy = throwerif enemy:attack( enemy). Loop # How do you find the nearest friendly unit? Horse = @ findNearest( @ findFriends)if horsex1 = horse. X - 7 x2 = horse. X + 7 if x1 = 1 # Move to the horse's y position but use x1 for the x position. @ moveXY x1, horse.
Y else if x2. # It seems like the Ogre Chieftain is stealing your gems!# Use the two artillery cannons to defeat your enemies and gather the gems.while True:enemy = hero. FindNearest( hero. FindEnemies)if enemy:enemyPos = enemy.
X + ' ' + enemy. Say( 'Enemy at: ' + enemyPos)# Now that you have sweet revenge, why not have your cake and eat it, too?# Find the item's position and say it for your artillery to target.item = hero. FindNearest( hero.
FindItems)if item:itemPos = item. X + ' ' + item. Say( 'Item at: ' + itemPos). # Move to 'Laszlo' and get his secret number.hero. MoveXY( 30, 13)las = hero. GetSecret# Add 7 to 'Laszlo's number to get 'Erzsebet's number.# Move to 'Erzsebet' and say her magic number.erz = las + 7hero.
MoveXY( 17, 26)hero. Say( erz)# Divide 'Erzsebet's number by 4 to get 'Simonyi's number.# Go to 'Simonyi' and tell him his number.sim = erz / 4;hero. MoveXY( 30, 39)hero. Say( sim)# Multiply 'Simonyi's number by 'Laszlo's to get 'Agata's number.# Go to 'Agata' and tell her her number.aga = sim. las;hero. MoveXY( 43, 26)hero. # Move to Eszter and get the secret number from her.hero.
MoveXY( 16, 32)secret = hero. FindNearest( hero. GetSecret# Follow the instructions to get the magic number!# Remember to use parentheses to do calculations in the right order.# Move to Tamas and say his magic number.hero. MoveXY( 24, 28)t = secret.
3 - 2hero. Little nightmares gameplay xbox. Say( t)# Move to Zsofi and say her magic number.hero. MoveXY( 32, 24)z =( t - 1).
4hero. Say( z)# Move to Istvan and say his magic number.hero. MoveXY( 40, 20)i =((( secret.
3 - 2) - 1). 4 + secret. 3 - 2) / 2hero. Say( i)# Move to Csilla and say her magic number.hero. MoveXY( 48, 16)hero. Say(( t + z).( z - i)). # This shows how to define a function called cleaveWhenClose# The function defines a parameter called targetdef cleaveWhenClose( target):if hero.
DistanceTo( target). # The function maybeBuildTrap defines TWO parameters!def maybeBuildTrap( x, y):# Use x and y as the coordinates to move to.hero. MoveXY( x, y)enemy = hero. FindNearestEnemyif enemy:#pass# Use buildXY to build a 'fire-trap' at the given x and y.hero. BuildXY( 'fire-trap', x, y)while True:# This calls maybeBuildTrap, with the coordinates of the top entrance.maybeBuildTrap( 43, 50)# Now use maybeBuildTrap at the left entrance!maybeBuildTrap( 25, 34)# Now use maybeBuildTrap at the bottom entrance!maybeBuildTrap( 43, 20). # Peons are trying to steal your coins!# Write a function to squash them before they can take your coins.def pickUpCoin:coin = hero. FindNearest( hero.
![Codecombat download game Codecombat download game](http://files.codecombat.com/presspack/gameimages/CodeCombat_Splash.png)
FindItems)if coin:hero. MoveXY( coin. Y)# Write the attackEnemy function below.# Find the nearest enemy and attack them if they exist!def attackEnemy:enemy = hero.
FindNearest( hero. FindEnemies)if enemy:hero. Attack( enemy)while True:attackEnemy # ∆ Uncomment this line after you write an attackEnemy function.pickUpCoin. # Another chest in the field for the hero to break open! # Attack the chest to break it open.
# Some munchkins won't stand idly by while you attack it! # Defend yourself when a munchkin gets too close. Loop enemy = @ findNearestEnemyif @ isReady 'cleave ' # First priority is to cleave if it's ready: @ cleave enemyelse if @ distanceTo enemy. # Another chest in the field for the hero to break open!# Attack the chest to break it open.# Some munchkins won't stand idly by while you attack it!# Defend yourself when a munchkin gets too close.while True:enemy = hero. FindNearestEnemydistance = hero. DistanceTo( enemy)if hero. IsReady( 'cleave'):# First priority is to cleave if it's ready:hero.
Cleave( enemy)elif distance. # Ogres are attacking a nearby settlement!# Be careful, though, for the ogres have sown the ground with poison.# Gather coins and defeat the ogres, but avoid the burls and poison!while True:enemy = hero. FindNearestEnemyif enemy. Type 'munchkin' or enemy. Type 'thrower':hero. Attack( enemy)item = hero.
FindNearestItem# Check the item type to make sure the hero doesn't pick up poison!# Look for types: 'gem' and 'coin'if item. Type 'gem' or item. Type 'coin':hero.
# Get two secret true/false values from the wizard.hero. MoveXY( 14, 24)secretA = hero. GetSecretAsecretB = hero. GetSecretB# If BOTH secretA and secretB are true, take the high path; otherwise, take the low path.# Check the guide for notes on how to write logical expressions.secretC = secretA and secretBif secretC:hero. MoveXY( 20, 33)else:hero.
MoveXY( 20, 15)hero. MoveXY( 26, 24)# If EITHER secretA or secretB is true, take the high path.if secretA or secretB:hero. MoveXY( 32, 33)else:hero. MoveXY( 32, 15)hero. MoveXY( 38, 24)# Take the OPPOSITE of secretB and follow its path.if not secretB:hero. MoveXY( 44, 33)else:hero.
MoveXY( 44, 15)hero. MoveXY( 50, 24).
# Move to the wizard and get their secret values.hero. MoveXY( 20, 24)secretA = hero. GetSecretAsecretB = hero.
GetSecretBsecretC = hero. GetSecretC# If ALL three values are true, take the high path.
Otherwise, take the low path.secretD = secretA and secretB and secretCif secretD:hero. MoveXY( 30, 33)else:hero. MoveXY( 30, 15)# If ANY of the three values are true, take the left path.
Otherwise, go right.if secretA or secretB or secretC:hero. MoveXY( 20, 24)else:hero. MoveXY( 40, 24)# If ALL of the LAST three values are true, take the high path.if secretA and secretB and secretC:hero. MoveXY( 30, 33)else:hero. MoveXY( 30, 15). # Try to get the best grade (gold) at the magic exam.# Move to each X mark, then use a spell.def action:friend = hero.
FindNearestFriendif friend:if friend. Type 'soldier':hero. Cast( 'heal', friend)elif friend. Type 'goliath':hero. Cast( 'grow', friend)else:hero. Cast( 'regen', friend)enemy = hero.
FindNearestEnemyif enemy:if enemy. Type 'ogre':hero. Cast( 'force-bolt', enemy)elif enemy. Type 'brawler':hero.
Cast( 'shrink', enemy)else:hero. Cast( 'poison-cloud', enemy)hero. MoveXY( 18, 24)actionhero. MoveXY( 18, 40)actionhero. MoveXY( 34, 24)actionhero.
MoveXY( 34, 40)actionhero. MoveXY( 50, 40)actionhero. MoveXY( 50, 24)actionhero. MoveXY( 66, 40)item = hero. Cast( 'grow', hero)hero.
![Download Download](/uploads/1/2/5/7/125750314/204015873.jpg)
MoveXY( item. MoveXY( 66, 24)item = hero. MoveXY( item.
![](/uploads/1/2/5/7/125750314/910463689.jpeg)