Skip to content

Instantly share code, notes, and snippets.

@libbyschuknight
Created August 3, 2015 04:28
Show Gist options
  • Select an option

  • Save libbyschuknight/f8f1d2252724e62b5b21 to your computer and use it in GitHub Desktop.

Select an option

Save libbyschuknight/f8f1d2252724e62b5b21 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
//run the code
// console.log("this is loading")
$(document).keyup(function(e) {
// console.log(e)
updatePlayerPosition(e.keyCode)
});
});
var player1Position = 0;
var player2Position = 0;
function updatePlayerPosition(key){
var player1strip = $('#player1_strip td');
var player2strip = $('#player2_strip td');
if (key === 65) {
player1Position += 1;
$(player1strip).removeClass("active_1");
$(player1strip[player1Position]).addClass("active_1");
} else if (key === 76) {
player2Position += 1;
$(player2strip).removeClass("active_2");
$(player2strip[player2Position]).addClass("active_2");
}
if(player1Position === $("#player1_strip td").length -1){
alert("Player One Wins!")
location.reload();
}
else if (player2Position === $("#player2_strip td").length -1){
alert("Player Two Wins!")
location.reload();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment