Created
August 3, 2015 04:28
-
-
Save libbyschuknight/f8f1d2252724e62b5b21 to your computer and use it in GitHub Desktop.
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
| $(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