disable button while game

This commit is contained in:
gnieark 2016-06-12 13:05:23 +02:00
parent 92db3755c5
commit be5b07fa9a
2 changed files with 10 additions and 2 deletions

View File

@ -21,10 +21,14 @@ function createElem(type,attributes){
function connectFour(bot1,bot2,xd_check, gameId, newGame){
if (newGame === undefined){
newGame = true;
gameId=0;
}
if (newGame){
gameId=0;
//don't touch the button while game is not ended
document.getElementById('fightButton').disabled=true;
//empty
while (document.getElementById('fightResult').firstChild) {
document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild);
@ -65,6 +69,7 @@ function connectFour(bot1,bot2,xd_check, gameId, newGame){
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
}
//colorise cells that win
if(reponse['cellsWin'] === undefined){
}else{
@ -79,12 +84,15 @@ function connectFour(bot1,bot2,xd_check, gameId, newGame){
//if game isn't finished, continue
if(reponse['continue'] == 1){
connectFour(bot1,bot2,xd_check,reponse['gameId'], false);
}else{
document.getElementById('fightButton').disabled=false;
}
}else if(xhr.status == 512){
//just forget
return;
}else{
alert ('error ' + xhr.status);
document.getElementById('fightButton').disabled=false;
return;
}
}};

View File

@ -23,5 +23,5 @@ $bots=get_Bots_Array('connectFou');
?>
</select>
</p>
<p><input type="button" value="<?php echo $lang['FIGHT']; ?>" onclick="connectFour(document.getElementById('bot1').value,document.getElementById('bot2').value,'<?php echo xd_check_input(2); ?>',0);"></p>
<p><input id="fightButton" type="button" value="<?php echo $lang['FIGHT']; ?>" onclick="connectFour(document.getElementById('bot1').value,document.getElementById('bot2').value,'<?php echo xd_check_input(2); ?>',0);"></p>
<div id="fightResult"></div>