samedi 27 décembre 2014

Elsif test on array

I thought I would try and make a noughts and crosses game to refresh my memory while I was off over Christmas "just for fun" and I've hit a block in the road.


The array holds either a 0 or a x so I am testing for three in a line. I thought maybe it was because I was testing to arrays against each other but I tested $array_cont_val[1][1] == $x as well with no joy.


Any help would be greatly appreciated



function who_won($array_cont_val){
$x = 23;
if($array_cont_val[1][1] == $array_cont_val[1][2] && $array_cont_val[1][3] == $array_cont_val[1][2]){
$x = "wins";
} elseif ($array_cont_val[2][1] == $array_cont_val[2][2] && $array_cont_val[2][3]) == $array_cont_val[2][2] {
$x = "wins";
}elseif($array_cont_val[3][1] == $array_cont_val[3][2] && $array_cont_val[3][3] == $array_cont_val[3][2]){
$x = "wins";
}elseif($array_cont_val[1][1] == $array_cont_val[2][1] && $array_cont_val[3][1] == $array_cont_val[2][1]){
$x = "wins";
}elseif($array_cont_val[1][2] == $array_cont_val[2][2] && $array_cont_val[3][2]) == $array_cont_val[2][2] {
$x = "wins";
}elseif{($array_cont_val[1][3] == $array_cont_val[2][3] && $array_cont_val[3][3] == $array_cont_val[2][3]){
$x = "wins";
}elseif{($array_cont_val[1][1] == $array_cont_val[2][2] && $array_cont_val[3][3] == $array_cont_val[2][2]){
$x = "wins";
}
}
}
}

Aucun commentaire:

Enregistrer un commentaire