connect four full js

This commit is contained in:
Gnieark 2016-06-06 23:37:13 +02:00
parent 01b07a582d
commit b8279dd421

View File

@ -43,7 +43,7 @@ pre{ font-style: normal;font-size: 16px; margin-left: 32px;font-family: Consolas
</style> </style>
<script> <script>
var grid=[["","","","","","",""], var board=[["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
@ -199,12 +199,33 @@ function startGame(){
document.getElementById('grid').appendChild(newTr); document.getElementById('grid').appendChild(newTr);
grid=[["","","","","","",""], board=[["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""], ["","","","","","",""],
["","","","","","",""]]; ["","","","","","",""]];
//send init messages
for (var p = 1; p < 3 ; p++){
if(document.getElementById("player" + p + "Type").value == "bot"){
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) {
addLog('Message d\'init envoyé au bot player ' + p );
}else{
addLog('player ' + p + ' n est pas joignable ' + xhr.status);
return;
}
}};
xhr.open("POST", document.getElementById('url' + p).value, false);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(' {"game-id":"1127","action":"init","game":"connectFour","players":2,"board":"","player-index":' + (p - 1) +'}');
}
}
play(1); play(1);
} }
</script> </script>