cohérance taill grille et nombre/taille des navires
This commit is contained in:
parent
b717a85e53
commit
30cd1bc199
|
@ -57,6 +57,10 @@ switch ($_POST['act']){
|
||||||
error (500,"missing parameter 2");
|
error (500,"missing parameter 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!is_it_possible_to_place_ships_on_grid($postValues['gridWidth'],$postValues['gridHeight'],$postValues['nbShip1'],$posValues['nbship2'],$postValues['nbship3'],$postValues['nbship4'],$postValues['nbship5'],$postvalues['nbship6'])){
|
||||||
|
error (404,"grid is too little for these sips");
|
||||||
|
}
|
||||||
|
|
||||||
//vars checked, lets init the initGame
|
//vars checked, lets init the initGame
|
||||||
|
|
||||||
$_SESSION['matchId']=get_unique_id();
|
$_SESSION['matchId']=get_unique_id();
|
||||||
|
|
|
@ -21,6 +21,28 @@ function createElem(type,attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){
|
function battleship(bot1,bot2,gridWidth,gridHeight,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6,xd_check){
|
||||||
|
|
||||||
|
var shipsArea=nbShip1 + 2 * nbShip2 + 3 * nbShip3 + 4 * nbShip4 + 5 * nbShip5 + 6 * nbShip6;
|
||||||
|
if(shipsArea > gridWidth * gridHeight / 2 ){
|
||||||
|
alert("Map is too small. Sum of ships areas must be under 50% of the map.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var ships= [0,nbShip1,nbShip2,nbShip3,nbShip4,nbShip5,nbShip6];
|
||||||
|
var longestShip=0;
|
||||||
|
for(var i = 6; i > 0; i--){
|
||||||
|
if(ships[i] > 0){
|
||||||
|
longestShip=ships[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if((longestShip==0)
|
||||||
|
||((longestShip > gridWidth) && (longestShip > gridHeight))
|
||||||
|
){
|
||||||
|
alert ("Map is too small. Grow it or reduce ships");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var bot1IdName = bot1.split("-");
|
var bot1IdName = bot1.split("-");
|
||||||
var bot2IdName = bot2.split("-");
|
var bot2IdName = bot2.split("-");
|
||||||
document.getElementById('fightResult').innerHTML = '';
|
document.getElementById('fightResult').innerHTML = '';
|
||||||
|
|
Loading…
Reference in New Issue
Block a user