var userNam;
var whoIsMove;
var playerColor;
var playerToMoveID;
var currentPlayerID = $("#currentPlayerID").val();
$(document).ready(function ()
{
//$("#moveMessage").html("Waiting for update...");
var refreshId = setInterval("GetMoves(), GetWhoIsMove()", 1000);
var to;
var from = 's65';
var pieceName;
playerColor = $("#playerColor").val();
currentPlayerID = $("#currentPlayerID").val();
/// playerToMoveID = $("#playerToMove").val();
if (currentPlayerID == playerToMoveID)
{
if (playerColor.toString() == "white")
{
$(".whiteP").draggable({
//revert: 'invalid',
//helper: 'clone',
cursor: 'move',
containment: 'checkerBoard',
start: function (event, ui)
{
//$(".square").hover(function ()
//{
// from = $(this).attr('id')
//});
pieceName = $(this).attr('id');
//alert($from);
}
});
} else if (playerColor.toString() == "black")
{
$(".blackP").draggable({
//revert: 'invalid',
//helper: 'clone',
cursor: 'move',
containment: 'checkerBoard',
start: function (event, ui)
{
//$(".square").hover(function ()
//{
// from = $(this).attr('id')
//});
pieceName = $(this).attr('id');
//alert($from);
}
});
}
}
$("div.square").droppable({
accept: '.chessPiece',
drop: function (event, ui)
{
to = $(this).attr('id');
//alert(currentPlayerID);
$.post(
"/Game/MakeMove",
{
To: to,
From: from,
PieceName: pieceName,
UserName: $("#userName").val(),
UserID1: $("#userID1").val(),
UserID2: $("#userID2").val(),
GameID: $("#gameID").val()
},
function (data)
{
if (data == 'good')
{ }
else if (data == 'bad')
{
alert("sorry not you turn");
}
}
);
}
});
})
function GetWhoIsMove()
{
$.getJSON(
"/Game/GetWhoIsMove",
{
GameID: $("#gameID").val()
},
function (data)
{
playerToMoveID = data;
}
);
}
That line is causing problems: if (currentPlayerID == playerToMoveID)
It always return false. I have checked values, and currentPlayerID is depeding on what player is curretnly logged in and playerToMoveID is pulled up from data base.
While I used those variables in alert(), they showed correct values for both players. So I must ask, what's wrong with that if() ?
It should be alwyas true for exactly one player, until he make his move.
setInterval.