Skip to content

Instantly share code, notes, and snippets.

@thinsoldier
Created September 25, 2015 21:09
Show Gist options
  • Save thinsoldier/856d146f2dc427fad79f to your computer and use it in GitHub Desktop.
Save thinsoldier/856d146f2dc427fad79f to your computer and use it in GitHub Desktop.
CodeCombat - Kithgard Dungeon - forgetful-gemsmith
// 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