I'm new to JS, trying to build a game based around switching a set of tiles back and forth between two players.
One is function intended to switch turns between two players. Another changes the tiles' color, using the turn variable to determine which color to switch to.
I don't think either is working.
Fiddle: http://jsfiddle.net/f5mEY/3
var currentPlayer;
var playerOne;
var playerTwo;
var turnCounter = 0;
//this function is intended to iterate between the two players when a player completes their turn by hitting submit
$(document).ready(function() {
$('#submit').click(function() {
turnCounter += 1;
if (turnCounter%2 === 0) {
currentPlayer = playerOne;
}
else {
currentPlayer = playerTwo;
}
});
});
//and this should turn the unplayed tiles to the correct player's color when they are clicked
$(document).ready(function() {
$('.unplayedTile').click(function() {
if (currentPlayer === playerOne) {
$(this).toggleClass('unplayedTile playerOneTile');
}
else {
$(this).toggleClass('unplayedTile playerTwoTile');
}
});
});
Many thanks in advance for any help!