This commit is contained in:
Gnieark 2016-06-07 12:30:45 +02:00
parent 9291dd7c19
commit 317d1d1984

View File

@ -147,6 +147,10 @@ function play(player){
var symbol="O"; var symbol="O";
} }
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){ xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) { if(xhr.status == 200) {
@ -162,10 +166,15 @@ function play(player){
die; die;
} }
}}; }};
xhr.open("POST", document.getElementById('url' + player).value, true); xhr.open("POST", document.getElementById('url' + player).value, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('game=connectFour&match_id=666-' + player + '&you=' + symbol + '&grid=' + JSON.stringify(grid) ); xhr.send('game=connectFour&match_id=666-' + player + '&you=' + symbol + '&grid=' + JSON.stringify(grid) );
}else{ }else{
//wait for human response, show buttons //wait for human response, show buttons
document.getElementById("playerButtons").setAttribute("class", ""); document.getElementById("playerButtons").setAttribute("class", "");
@ -214,13 +223,14 @@ function startGame(){
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":"1127","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'}'); xhr.send(' {"game-id":"1127","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 );
addLog('Message d\'init envoyé au bot player ' + p ); }else{
}else{ addLog('player ' + p + ' n est pas joignable ' + xhr.status);
addLog('player ' + p + ' n est pas joignable ' + xhr.status); return;
return; }
} }
} }
play(1); play(1);