Created
September 25, 2015 21:09
-
-
Save thinsoldier/856d146f2dc427fad79f to your computer and use it in GitHub Desktop.
CodeCombat - Kithgard Dungeon - forgetful-gemsmith
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://codecombat.com/play/level/forgetful-gemsmith | |
// This function allows passing in a string of directions | |
// which will be converted into calls to the standard | |
// this.move____() functions. | |
this.moveSequence = function( instructions ) | |
{ | |
// Remove spaces from the instructions using a "greedy" Regular Expression. | |
var clean_instructions = instructions.replace( / /g, '' ); | |
// Break the instructions into an array list, 1 letter per array item. | |
var actions = clean_instructions.split(''); | |
// Loop through the list and perform an action based on which letter is found. | |
for( var i = 0; i< actions.length; i++ ) | |
{ | |
switch( actions[i] ) | |
{ | |
case 'L': this.moveLeft(); break; | |
case 'R': this.moveRight(); break; | |
case 'U': this.moveUp(); break; | |
case 'D': this.moveDown(); break; | |
} | |
} | |
}; | |
// Use the moveSequence function to walk to the exit. | |
this.moveSequence("R U R R D D U R"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment