clean code

This commit is contained in:
gnieark 2016-05-15 14:31:50 +02:00
parent 553183b781
commit dfcaed4beb
2 changed files with 8 additions and 10 deletions

View File

@ -198,7 +198,7 @@ switch ($_POST['act']){
'strikeX' => $strikeX, 'strikeX' => $strikeX,
'strikeY' => $strikeY, 'strikeY' => $strikeY,
'strikeSymbol'=> $you, 'strikeSymbol'=> $you,
'log' => $you." ".$currentBotName." a gagné" 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer"et a gagné"
); );
}else{ }else{
$anwserToJS=array( $anwserToJS=array(

View File

@ -29,7 +29,6 @@ function connectFour(bot1,bot2,xd_check, newGame){
document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild); document.getElementById('fightResult').removeChild(document.getElementById('fightResult').firstChild);
} }
//create grid //create grid
var table=createElem('table',{'class':'battleGrid'}); var table=createElem('table',{'class':'battleGrid'});
for (var i=6; i > -1; i--){ for (var i=6; i > -1; i--){
var tr=createElem('tr'); var tr=createElem('tr');
@ -42,28 +41,27 @@ function connectFour(bot1,bot2,xd_check, newGame){
} }
document.getElementById('fightResult').appendChild(table); document.getElementById('fightResult').appendChild(table);
} }
//send request
var xhr = Ajx(); var xhr = Ajx();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){ xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) { if(xhr.status == 200) {
//for debug
document.getElementById('logs').innerHTML += xhr.responseText + '<br/>';
try{ try{
var reponse = JSON.parse(xhr.responseText); var reponse = JSON.parse(xhr.responseText);
}catch(e){ }catch(e){
document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText; document.getElementById('logs').innerHTML += 'erreur' +xhr.responseText;
return; return;
} }
//log
document.getElementById('logs').innerHTML += reponse['log'] + '<br/>';
//fill the grid //fill the grid
if( reponse['strikeX'] > -1){ if( reponse['strikeX'] > -1){
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol']; document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
} }
//if game isn't finished, continue
if(reponse['continue'] == 1){ if(reponse['continue'] == 1){
connectFour(bot1,bot2,xd_check, false); connectFour(bot1,bot2,xd_check, false);
} }
}else{ }else{
alert ('error ' + xhr.status); alert ('error ' + xhr.status);
return; return;