log
This commit is contained in:
parent
99bb80c3e2
commit
376e767449
|
@ -43,10 +43,12 @@ switch ($_POST['act']){
|
|||
if($bot['id'] == $_POST['bot1']){
|
||||
|
||||
$bot1 = $bot;
|
||||
$_SESSION['bot1']=$bot;
|
||||
$bot1Exists =true;
|
||||
}
|
||||
if($bot['id'] == $_POST['bot2']){
|
||||
$bot2 = $bot;
|
||||
$_SESSION['bot2']=$bot;
|
||||
$bot2Exists =true;
|
||||
}
|
||||
if ($bot1Exists && $bot2Exists){
|
||||
|
@ -134,6 +136,33 @@ switch ($_POST['act']){
|
|||
}
|
||||
die;
|
||||
}
|
||||
//remember each cases of each boats
|
||||
$boatListOfCases=array();
|
||||
if($xStart == $xEnd){
|
||||
if($yStart <= $yEnd ){
|
||||
$start=$yStart;
|
||||
$end=$yEnd;
|
||||
}else{
|
||||
$start=$yEnd;
|
||||
$end=$yStart;
|
||||
}
|
||||
for($i = $start; $i <= $end; $i++){
|
||||
$boatListOfCases[]=$xStart.",".$i;
|
||||
}
|
||||
}else{
|
||||
if($xStart <= $xEnd ){
|
||||
$start=$xStart;
|
||||
$end=$xEnd;
|
||||
}else{
|
||||
$start=$xEnd;
|
||||
$end=$xStart;
|
||||
}
|
||||
for($i = $start; $i <= $end; $i++){
|
||||
$boatListOfCases[]=$i.",".$yStart;
|
||||
}
|
||||
|
||||
}
|
||||
$_SESSION['ships'][$player][]=$boatListOfCases;
|
||||
}
|
||||
foreach($nbBoatsIwant as $nb){
|
||||
if($nb <> 0){
|
||||
|
@ -148,11 +177,17 @@ switch ($_POST['act']){
|
|||
}
|
||||
}
|
||||
|
||||
//$_SESSION['grids']=$grid;
|
||||
$_SESSION['shots'][1]=array();
|
||||
$_SESSION['shots'][2]=array();
|
||||
$_SESSION['width']=$postValues['gridWidth'];
|
||||
$_SESSION['height']=$postValues['gridHeight'];
|
||||
echo json_encode($grid); die;
|
||||
|
||||
die;
|
||||
|
||||
break;
|
||||
case "fight";
|
||||
print_r($_SESSION);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -19,6 +19,23 @@ function createElem(type,attributes)
|
|||
{elem.setAttribute(i,attributes[i]);}
|
||||
return elem;
|
||||
}
|
||||
function fight(xd_check){
|
||||
var xhr = Ajx();
|
||||
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
||||
if(xhr.status == 200) {
|
||||
var p=createElem("p");
|
||||
p.innerHTML=xhr.responseText;
|
||||
document.getElementById('logs').appendChild(p);
|
||||
fight(xd_check);
|
||||
|
||||
}
|
||||
|
||||
}};
|
||||
xhr.open("POST", '/Battleship', true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
xhr.send('act=fight&xd_check=' + xd_check);
|
||||
|
||||
}
|
||||
|
||||
function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){
|
||||
|
||||
|
@ -104,7 +121,7 @@ function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShi
|
|||
var p=createElem("p");
|
||||
p.innerHTML='players placed theirs ships';
|
||||
document.getElementById('logs').appendChild(p);
|
||||
|
||||
fight(xd_check);
|
||||
}
|
||||
|
||||
}};
|
||||
|
|
Loading…
Reference in New Issue
Block a user