commit
dc781e1ded
|
@ -222,7 +222,7 @@ function play(player){
|
||||||
var arrToSend= {
|
var arrToSend= {
|
||||||
"game-id": "" + gameId,
|
"game-id": "" + gameId,
|
||||||
"action" : "play-turn",
|
"action" : "play-turn",
|
||||||
"game" : "connectfour",
|
"game" : "connectFour",
|
||||||
"players" : 2,
|
"players" : 2,
|
||||||
"board" : board,
|
"board" : board,
|
||||||
"you" : symbol,
|
"you" : symbol,
|
||||||
|
@ -301,9 +301,9 @@ function startGame(){
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("POST", document.getElementById('url' + p).value, false);
|
xhr.open("POST", document.getElementById('url' + p).value, false);
|
||||||
xhr.setRequestHeader("Content-Type", "application/json");
|
xhr.setRequestHeader("Content-Type", "application/json");
|
||||||
xhr.send(' {"game-id":"' + gameId + '","action":"init","game":"connectfour","players":2,"board":"","player-index":' + (p - 1) +'}');
|
xhr.send(' {"game-id":"' + gameId + '","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'}');
|
||||||
if(xhr.status == 200) {
|
if(xhr.status == 200) {
|
||||||
addLog('Message d\'init envoyé au bot player ' + p + ' {"game-id":"' + gameId + '","action":"init","game":"connectfour","players":2,"board":"","player-index":' + (p - 1) +'} <br/> il a répondu ' + xhr.responseText );
|
addLog('Message d\'init envoyé au bot player ' + p + ' {"game-id":"' + gameId + '","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'} <br/> il a répondu ' + xhr.responseText );
|
||||||
}else{
|
}else{
|
||||||
addLog('player ' + p + ' n est pas joignable ' + xhr.status);
|
addLog('player ' + p + ' n est pas joignable ' + xhr.status);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
require_once(__DIR__."/functions.php");
|
require_once(__DIR__."/functions.php");
|
||||||
$bots=get_Bots_Array('connectFou');
|
$bots=get_Bots_Array('connectFou');
|
||||||
|
$new=false;
|
||||||
switch ($_POST['act']){
|
switch ($_POST['act']){
|
||||||
|
|
||||||
case "newFight":
|
case "newFight":
|
||||||
|
$new=true;
|
||||||
//remove $_SESSION less xd_check
|
//remove $_SESSION less xd_check
|
||||||
$xd=$_SESSION['xd_check'];
|
$xd=$_SESSION['xd_check'];
|
||||||
session_unset();
|
session_unset();
|
||||||
|
@ -64,12 +65,14 @@ switch ($_POST['act']){
|
||||||
get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result
|
get_IA_Response($_SESSION['bot2']['url'],$params[1]); //don't care about result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//echo "plop".json_encode($_SESSION['map']);
|
|
||||||
case "fight":
|
case "fight":
|
||||||
|
|
||||||
if($_SESSION['game'] <> "connectFou"){
|
if($_SESSION['game'] <> "connectFou"){
|
||||||
error(500,"game non found");
|
error(500,"game non found");
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
if((!$new) && ($_POST['gameId'] <> $_SESSION['matchId'])){
|
||||||
|
error (512, "not correct gameId");
|
||||||
}
|
}
|
||||||
|
|
||||||
//What player has to play?
|
//What player has to play?
|
||||||
|
@ -245,7 +248,8 @@ switch ($_POST['act']){
|
||||||
'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)
|
'cellsWin' => json_encode($cellsWin),
|
||||||
|
'gameId' => $_SESSION['matchId']
|
||||||
);
|
);
|
||||||
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);
|
||||||
|
@ -273,7 +277,8 @@ switch ($_POST['act']){
|
||||||
'strikeX' => $strikeX,
|
'strikeX' => $strikeX,
|
||||||
'strikeY' => $strikeY,
|
'strikeY' => $strikeY,
|
||||||
'strikeSymbol'=> $you,
|
'strikeSymbol'=> $you,
|
||||||
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." match nul"
|
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer." match nul",
|
||||||
|
'gameId' => $_SESSION['matchId']
|
||||||
);
|
);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
|
@ -283,7 +288,8 @@ switch ($_POST['act']){
|
||||||
'strikeX' => $strikeX,
|
'strikeX' => $strikeX,
|
||||||
'strikeY' => $strikeY,
|
'strikeY' => $strikeY,
|
||||||
'strikeSymbol'=> $you,
|
'strikeSymbol'=> $you,
|
||||||
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer
|
'log' => $you." ".$currentBotName." joue colonne ". $anwserPlayer,
|
||||||
|
'gameId' => $_SESSION['matchId']
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -294,7 +300,8 @@ switch ($_POST['act']){
|
||||||
'continue' =>0,
|
'continue' =>0,
|
||||||
'strikeX' => -1,
|
'strikeX' => -1,
|
||||||
'strikeY' => -1,
|
'strikeY' => -1,
|
||||||
'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd"
|
'log' => $you." ".$currentBotName." a fait une réponse non conforme, il perd".json_encode($tempPlayer),
|
||||||
|
'gameId' => $_SESSION['matchId']
|
||||||
);
|
);
|
||||||
if($_SESSION['currentPlayer']==1){
|
if($_SESSION['currentPlayer']==1){
|
||||||
save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2);
|
save_battle('connectFou',$_SESSION['bot1']['name'],$_SESSION['bot2']['name'],2);
|
||||||
|
|
|
@ -18,9 +18,10 @@ function createElem(type,attributes){
|
||||||
{elem.setAttribute(i,attributes[i]);}
|
{elem.setAttribute(i,attributes[i]);}
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
function connectFour(bot1,bot2,xd_check, newGame){
|
function connectFour(bot1,bot2,xd_check, gameId, newGame){
|
||||||
if (newGame === undefined){
|
if (newGame === undefined){
|
||||||
newGame = true;
|
newGame = true;
|
||||||
|
gameId=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newGame){
|
if (newGame){
|
||||||
|
@ -58,6 +59,7 @@ function connectFour(bot1,bot2,xd_check, newGame){
|
||||||
}
|
}
|
||||||
//log
|
//log
|
||||||
document.getElementById('logs').innerHTML += reponse['log'] + '<br/>';
|
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'];
|
||||||
|
@ -76,8 +78,11 @@ function connectFour(bot1,bot2,xd_check, newGame){
|
||||||
|
|
||||||
//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,reponse['gameId'], false);
|
||||||
}
|
}
|
||||||
|
}else if(xhr.status == 512){
|
||||||
|
//just forget
|
||||||
|
return;
|
||||||
}else{
|
}else{
|
||||||
alert ('error ' + xhr.status);
|
alert ('error ' + xhr.status);
|
||||||
return;
|
return;
|
||||||
|
@ -90,5 +95,5 @@ function connectFour(bot1,bot2,xd_check, newGame){
|
||||||
}else{
|
}else{
|
||||||
var act='fight';
|
var act='fight';
|
||||||
}
|
}
|
||||||
xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check);
|
xhr.send('act=' + act + '&bot1=' + bot1 + '&bot2=' + bot2 + '&xd_check=' + xd_check + '&gameId=' + gameId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,5 +23,5 @@ $bots=get_Bots_Array('connectFou');
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</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); ?>');"></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>
|
||||||
<div id="fightResult"></div>
|
<div id="fightResult"></div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user