404 Tech Support

Play CodeCombat to learn object-oriented programming

CodeCombat is a non-traditional game where you control a character in a fantasy battle against ogres and the like. The trick to the game is that you control the character by writing JavaScript. You can make them move, say things, attack enemies, and other functions all with the corresponding lines of code like:

this.moveXY(34, 65);

That would move the character selected to the X,Y coordinates of 34,65.

Don’t know how to code? No worries, the beginner rounds walk you through everything you need to know. The functions you can use are all available in the lower-right corner and you can hover over them with your mouse to learn more about them.

Immediately beneath where you enter your code, there is a Spell Cast button. I recommend clicking the gear and changing the setting to manual. That defines how often your code is “compiled” and the character acts it out. If you have several lines of code to write, it seems silly (and bug-causing) to have the character act each one out. I prefer being able to type all the lines and then click the Spell Cast button to have the character obey. Then, if you made a mistake, you can use the timeline underneath the combat screen to go back in time, correct your code, and then have them act out again.

You can play CodeCombat at www.codecombat.com. You can select which level you would like to play or just go through all the levels by clicking the Play button.

This video provides a quick example of playing through a level where I move the character closer to taunt the enemy and then retreat to lure them into a trap. Other levels are different and introduce the use of strings, understanding comments, or other functions.

CodeCombat is open-source. It currently includes a beginner campaign, some more challenging levels, and a few player-contributed levels. Try it out at www.codecombat.com