colorise cases when wins
This commit is contained in:
parent
16e77e03da
commit
5fb2da47e7
|
@ -91,8 +91,6 @@ switch ($_POST['act']){
|
||||||
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
|
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
|
||||||
|
|
||||||
//vérifier la validité de la réponse
|
//vérifier la validité de la réponse
|
||||||
|
|
||||||
|
|
||||||
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
||||||
//reponse conforme
|
//reponse conforme
|
||||||
|
|
||||||
|
@ -109,10 +107,13 @@ switch ($_POST['act']){
|
||||||
$count=1;
|
$count=1;
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
|
$cellsWin=array();
|
||||||
|
$cellsWin[]=array($x,$y);
|
||||||
while(($x > 0) && ($y < 5) && ($_SESSION['map'][$y + 1][$x - 1] == $you)){
|
while(($x > 0) && ($y < 5) && ($_SESSION['map'][$y + 1][$x - 1] == $you)){
|
||||||
$x--;
|
$x--;
|
||||||
$y++;
|
$y++;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x - 1,$y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
|
@ -121,6 +122,7 @@ switch ($_POST['act']){
|
||||||
$x++;
|
$x++;
|
||||||
$y--;
|
$y--;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x + 1,$y - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($count>3){
|
if($count>3){
|
||||||
|
@ -129,14 +131,17 @@ switch ($_POST['act']){
|
||||||
|
|
||||||
//diagonale /
|
//diagonale /
|
||||||
if(!$wins){
|
if(!$wins){
|
||||||
|
|
||||||
$count=1;
|
$count=1;
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
|
$cellsWin =array();
|
||||||
|
$cellsWin[]=array($x ,$y);
|
||||||
while(($x < 6) && ($y < 5) && ($_SESSION['map'][$y + 1][$x + 1 ] == $you)){
|
while(($x < 6) && ($y < 5) && ($_SESSION['map'][$y + 1][$x + 1 ] == $you)){
|
||||||
$x++;
|
$x++;
|
||||||
$y++;
|
$y++;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x + 1 ,$y -1);
|
||||||
}
|
}
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
|
@ -144,6 +149,7 @@ switch ($_POST['act']){
|
||||||
$x--;
|
$x--;
|
||||||
$y--;
|
$y--;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x + 1 ,$y -1);
|
||||||
}
|
}
|
||||||
if($count>3){
|
if($count>3){
|
||||||
$wins=true;
|
$wins=true;
|
||||||
|
@ -156,15 +162,19 @@ switch ($_POST['act']){
|
||||||
$count=1;
|
$count=1;
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
|
$cellsWin =array();
|
||||||
|
$cellsWin[]=array($x ,$y);
|
||||||
while(($x < 6) && ($_SESSION['map'][$y][$x + 1 ] == $you)){
|
while(($x < 6) && ($_SESSION['map'][$y][$x + 1 ] == $you)){
|
||||||
$x++;
|
$x++;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x +1 ,$y);
|
||||||
}
|
}
|
||||||
|
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
while(($x >0) && ($_SESSION['map'][$y][$x - 1 ] == $you)){
|
while(($x >0) && ($_SESSION['map'][$y][$x - 1 ] == $you)){
|
||||||
$count++;
|
$count++;
|
||||||
$x--;
|
$x--;
|
||||||
|
$cellsWin[]=array($x -1,$y);
|
||||||
}
|
}
|
||||||
if($count>3){
|
if($count>3){
|
||||||
$wins=true;
|
$wins=true;
|
||||||
|
@ -176,15 +186,21 @@ switch ($_POST['act']){
|
||||||
$count=1;
|
$count=1;
|
||||||
$x=$strikeX;
|
$x=$strikeX;
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
|
|
||||||
|
$cellsWin =array();
|
||||||
|
$cellsWin[]=array($x ,$y);
|
||||||
|
|
||||||
while(($y < 5) && ($_SESSION['map'][$y + 1 ][$x] == $you)){
|
while(($y < 5) && ($_SESSION['map'][$y + 1 ][$x] == $you)){
|
||||||
$y++;
|
$y++;
|
||||||
$count++;
|
$count++;
|
||||||
|
$cellsWin[]=array($x ,$y + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$y=$strikeY;
|
$y=$strikeY;
|
||||||
while(($y >0) && ($_SESSION['map'][$y - 1][$x] == $you)){
|
while(($y >0) && ($_SESSION['map'][$y - 1][$x] == $you)){
|
||||||
$count++;
|
$count++;
|
||||||
$y--;
|
$y--;
|
||||||
|
$cellsWin[]=array($x ,$y -1);
|
||||||
}
|
}
|
||||||
if($count>3){
|
if($count>3){
|
||||||
$wins=true;
|
$wins=true;
|
||||||
|
@ -198,7 +214,8 @@ switch ($_POST['act']){
|
||||||
'strikeX' => $strikeX,
|
'strikeX' => $strikeX,
|
||||||
'strikeY' => $strikeY,
|
'strikeY' => $strikeY,
|
||||||
'strikeSymbol'=> $you,
|
'strikeSymbol'=> $you,
|
||||||
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné"
|
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné",
|
||||||
|
'cellsWin' => json_encode($cellsWin);
|
||||||
);
|
);
|
||||||
if($_SESSION['currentPlayer']==1){
|
if($_SESSION['currentPlayer']==1){
|
||||||
save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1);
|
save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1);
|
||||||
|
|
|
@ -60,6 +60,17 @@ function connectFour(bot1,bot2,xd_check, newGame){
|
||||||
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
|
document.getElementById('td' + reponse['strikeX'] + '_' + reponse['strikeY']).innerHTML = reponse['strikeSymbol'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(reponse['cellsWin'] === undefined){
|
||||||
|
|
||||||
|
}else{
|
||||||
|
var cellsWin = JSON.parse(reponse['cellsWin']);
|
||||||
|
for(var i in cellsWin){
|
||||||
|
document.getElementById('td' + cellsWin[i][0] + '_' + cellsWin[i][1]).setAttribute('class','winCase');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//if game isn't finished, continue
|
//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);
|
||||||
|
|
|
@ -5,3 +5,4 @@
|
||||||
.battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;}
|
.battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;}
|
||||||
.battleGrid tr{}
|
.battleGrid tr{}
|
||||||
.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;}
|
.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;}
|
||||||
|
.winCase{background-color:red;}
|
Loading…
Reference in New Issue
Block a user