public/js-roguelike-skeleton/manual/index/entity/js/basic-movement.js
function(currentDirection){
            var directions = ['up', 'right', 'down', 'left'],
                currentDirIndex = directions.indexOf(currentDirection),
                newDirIndex;
            // if currentDirection is not valid or is the last in the array use the first direction in the array
            if(currentDirIndex === -1 || currentDirIndex === directions.length - 1){
                newDirIndex = 0;
            } else {
                newDirIndex = currentDirIndex + 1;
            }
            return directions[newDirIndex];
        }
function(currentDirection){
            var directions = ['up', 'right', 'down', 'left'],
                currentDirIndex = directions.indexOf(currentDirection),
                newDirIndex;
            // if currentDirection is not valid or is the last in the array use the first direction in the array
            if(currentDirIndex === -1 || currentDirIndex === directions.length - 1){
                newDirIndex = 0;
            } else {
                newDirIndex = currentDirIndex + 1;
            }
            return directions[newDirIndex];
        }
function ( currentDirection ) { var directions = [ 'up' , 'right' , 'down' , 'left' ] , currentDirIndex = directions . indexOf ( currentDirection ) , newDirIndex ; // if currentDirection is not valid or is the last in the array use the first direction in the array if ( currentDirIndex === - 1 || currentDirIndex === directions . length - 1 ) { newDirIndex = 0 ; } else { newDirIndex = currentDirIndex + 1 ; } return directions [ newDirIndex ] ; }
Gets the next direction in the list
@method getNextDirection
@param {String} direction - The current direction.
@return {String}
Gets the next direction in the list