1
0
idizian db
This code is used to check if the player has reached the final row of the table. If the player has not reached the final row, the code checks to see if the player has reached the middle row. If the player has not reached the middle row, the code checks to see if the player has reached the first row. If the player has not reached the first row, the code sets the variable "empat" to true.
Shortcut: posarfila
function posarFila($columna)
{
//echo $columna;
$posada = false;
$i = count($_SESSION["tauler"]) - 1;
$guanyat = false;
while ($posada == false && $i >= 0) {
if ($_SESSION["tauler"][$i][$columna] == "0") {
if ($_SESSION["jugador"] == "1") {
$_SESSION["tauler"][$i][$columna] = 1;
$posada = true;
} else {
$_SESSION["tauler"][$i][$columna] = 2;
$posada = true;
}
} else {
}
$i--;
}
if ($posada == true) {
$guanyat = comprovarVertical($columna);
if ($guanyat == false) {
$guanyat = comprovarHoritzontal($i + 1);
if ($guanyat == false) {
$guanyat = comprovarDiagonal($i + 1, $columna);
if ($guanyat == false) {
if ($_SESSION["jugador"] == "1") {
$_SESSION["jugador"] = "2";
} else {
$_SESSION["jugador"] = "1";
}
}
}
}
}
if(!in_array("0",$_SESSION["tauler"][0])){
$_SESSION["empat"]=true;
}
return $guanyat;
}