From 5fb2da47e741b4e0e958f377b7569f7390f0c1a7 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 16 May 2016 23:35:43 +0200 Subject: [PATCH 1/3] colorise cases when wins --- src/arenas/connectFour/act.php | 25 +++++++++++++++++++++---- src/arenas/connectFour/js.js | 11 +++++++++++ src/arenas/connectFour/style.css | 3 ++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index badd5e1..f61ae18 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -91,8 +91,6 @@ switch ($_POST['act']){ $anwserPlayer=get_IA_Response($botUrl,$postDatas); //vérifier la validité de la réponse - - if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){ //reponse conforme @@ -109,10 +107,13 @@ switch ($_POST['act']){ $count=1; $x=$strikeX; $y=$strikeY; + $cellsWin=array(); + $cellsWin[]=array($x,$y); while(($x > 0) && ($y < 5) && ($_SESSION['map'][$y + 1][$x - 1] == $you)){ $x--; $y++; $count++; + $cellsWin[]=array($x - 1,$y + 1); } $x=$strikeX; @@ -121,6 +122,7 @@ switch ($_POST['act']){ $x++; $y--; $count++; + $cellsWin[]=array($x + 1,$y - 1); } if($count>3){ @@ -129,14 +131,17 @@ switch ($_POST['act']){ //diagonale / if(!$wins){ + $count=1; $x=$strikeX; $y=$strikeY; - + $cellsWin =array(); + $cellsWin[]=array($x ,$y); while(($x < 6) && ($y < 5) && ($_SESSION['map'][$y + 1][$x + 1 ] == $you)){ $x++; $y++; $count++; + $cellsWin[]=array($x + 1 ,$y -1); } $x=$strikeX; $y=$strikeY; @@ -144,6 +149,7 @@ switch ($_POST['act']){ $x--; $y--; $count++; + $cellsWin[]=array($x + 1 ,$y -1); } if($count>3){ $wins=true; @@ -156,15 +162,19 @@ switch ($_POST['act']){ $count=1; $x=$strikeX; $y=$strikeY; + $cellsWin =array(); + $cellsWin[]=array($x ,$y); while(($x < 6) && ($_SESSION['map'][$y][$x + 1 ] == $you)){ $x++; $count++; + $cellsWin[]=array($x +1 ,$y); } $x=$strikeX; while(($x >0) && ($_SESSION['map'][$y][$x - 1 ] == $you)){ $count++; $x--; + $cellsWin[]=array($x -1,$y); } if($count>3){ $wins=true; @@ -176,15 +186,21 @@ switch ($_POST['act']){ $count=1; $x=$strikeX; $y=$strikeY; + + $cellsWin =array(); + $cellsWin[]=array($x ,$y); + while(($y < 5) && ($_SESSION['map'][$y + 1 ][$x] == $you)){ $y++; $count++; + $cellsWin[]=array($x ,$y + 1); } $y=$strikeY; while(($y >0) && ($_SESSION['map'][$y - 1][$x] == $you)){ $count++; $y--; + $cellsWin[]=array($x ,$y -1); } if($count>3){ $wins=true; @@ -198,7 +214,8 @@ switch ($_POST['act']){ 'strikeX' => $strikeX, 'strikeY' => $strikeY, '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){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); diff --git a/src/arenas/connectFour/js.js b/src/arenas/connectFour/js.js index 58e6939..15ea2be 100644 --- a/src/arenas/connectFour/js.js +++ b/src/arenas/connectFour/js.js @@ -60,6 +60,17 @@ function connectFour(bot1,bot2,xd_check, newGame){ 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(reponse['continue'] == 1){ connectFour(bot1,bot2,xd_check, false); diff --git a/src/arenas/connectFour/style.css b/src/arenas/connectFour/style.css index 7017dda..489ba8d 100644 --- a/src/arenas/connectFour/style.css +++ b/src/arenas/connectFour/style.css @@ -4,4 +4,5 @@ #logs{display:block;padding-left:10px; height: 200px; overflow-y: scroll;} .battleGrid{display:table-cell; padding-left:10px; border-collapse:collapse; margin: 20px 20px 20px 20px;} .battleGrid tr{} -.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;} \ No newline at end of file +.battleGrid tr td{border: 1px dashed green; text-align: center; font-weight: bold;min-width:20px; height:20px;} +.winCase{background-color:red;} \ No newline at end of file From 5c6a3ec5476b4ac41d7ec4a579fb92ff362f723d Mon Sep 17 00:00:00 2001 From: Gnieark Date: Mon, 16 May 2016 23:36:41 +0200 Subject: [PATCH 2/3] fix php parse errror --- src/arenas/connectFour/act.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index f61ae18..ece917f 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -215,7 +215,7 @@ switch ($_POST['act']){ 'strikeY' => $strikeY, 'strikeSymbol'=> $you, 'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." et a gagné", - 'cellsWin' => json_encode($cellsWin); + 'cellsWin' => json_encode($cellsWin) ); if($_SESSION['currentPlayer']==1){ save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],1); From fbf7c7498792599d56999450d8ab9f945086f9e1 Mon Sep 17 00:00:00 2001 From: gnieark Date: Sat, 21 May 2016 22:30:15 +0200 Subject: [PATCH 3/3] fix win cells coords --- src/arenas/connectFour/act.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/arenas/connectFour/act.php b/src/arenas/connectFour/act.php index ece917f..d4b5f6c 100644 --- a/src/arenas/connectFour/act.php +++ b/src/arenas/connectFour/act.php @@ -113,7 +113,7 @@ switch ($_POST['act']){ $x--; $y++; $count++; - $cellsWin[]=array($x - 1,$y + 1); + $cellsWin[]=array($x,$y); } $x=$strikeX; @@ -122,7 +122,7 @@ switch ($_POST['act']){ $x++; $y--; $count++; - $cellsWin[]=array($x + 1,$y - 1); + $cellsWin[]=array($x,$y); } if($count>3){ @@ -141,7 +141,7 @@ switch ($_POST['act']){ $x++; $y++; $count++; - $cellsWin[]=array($x + 1 ,$y -1); + $cellsWin[]=array($x,$y); } $x=$strikeX; $y=$strikeY; @@ -149,7 +149,7 @@ switch ($_POST['act']){ $x--; $y--; $count++; - $cellsWin[]=array($x + 1 ,$y -1); + $cellsWin[]=array($x,$y); } if($count>3){ $wins=true; @@ -167,14 +167,14 @@ switch ($_POST['act']){ while(($x < 6) && ($_SESSION['map'][$y][$x + 1 ] == $you)){ $x++; $count++; - $cellsWin[]=array($x +1 ,$y); + $cellsWin[]=array($x,$y); + } - $x=$strikeX; while(($x >0) && ($_SESSION['map'][$y][$x - 1 ] == $you)){ $count++; $x--; - $cellsWin[]=array($x -1,$y); + $cellsWin[]=array($x,$y); } if($count>3){ $wins=true; @@ -193,14 +193,14 @@ switch ($_POST['act']){ while(($y < 5) && ($_SESSION['map'][$y + 1 ][$x] == $you)){ $y++; $count++; - $cellsWin[]=array($x ,$y + 1); + $cellsWin[]=array($x,$y); } $y=$strikeY; while(($y >0) && ($_SESSION['map'][$y - 1][$x] == $you)){ $count++; $y--; - $cellsWin[]=array($x ,$y -1); + $cellsWin[]=array($x,$y); } if($count>3){ $wins=true;