Skip to content

Instantly share code, notes, and snippets.

@bernatfortet bernatfortet/2048.js
Created Mar 11, 2014

Embed
What would you like to do?
function pressUp(){
pressKey('up');
}
function pressRight(){
pressKey('right');
}
function pressDown(){
pressKey('down');
}
function pressLeft(){
pressKey('left');
}
function pressLeft(){
pressKey('space');
}
function pressKey(key){
var e = jQuery.Event("keydown");
switch( key ){
case 'up':
e.which = 38;
break;
case 'right':
e.which = 39;
break;
case 'down':
e.which = 40;
break;
case 'left':
e.which = 37;
break;
case 'space':
e.which = 32;
break;
}
e.keyCode = e.which;
$("body").trigger(e);
}
function anaylize(){
setTimeout( function(){
pressDown();
anaylize();
}, 200 )
}
anaylize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.