本文实例讲述了php实现的简易扫雷游戏。分享给大家供大家参考。具体如下:
= 0 && $j - 1 >= 0 && $data["data".($i - 1)."_".($j - 1)] == 100)$cnt++;//upper left
if($i - 1 >= 0 && $data["data".($i - 1)."_".$j] == 100)$cnt++;//left
if($i - 1 >= 0 && $j + 1 < $cols && $data["data".($i - 1)."_".($j + 1)] == 100)$cnt++;//lower left
if($j - 1 >= 0 && $data["data".$i."_".($j - 1)] == 100)$cnt++;//upper
if($j + 1 < $cols && $data["data".$i."_".($j + 1)] == 100)$cnt++;//lower
if($i + 1 < $rows && $j - 1 >= 0 && $data["data".($i + 1)."_".($j - 1)] == 100)$cnt++;//upper right
if($i + 1 < $rows && $data["data".($i + 1)."_".$j] == 100)$cnt++;//right
if($i + 1 < $rows && $j + 1 < $cols && $data["data".($i + 1)."_".($j + 1)] == 100)$cnt++;//lower right
$data["data".$i."_".$j] = $cnt;//set number
}
}
}else{
$data = $_POST;//get data
if($data["data".$clickvalue] == 100){
//check the value of users click
$checkflag = 2;//if click on a mine,gameover
for($i=0;$i9?$min:"0".$min).":".($sec>9?$sec:"0".$sec);
}else{
$timeshow = "00:00";//if game is stop , time stop
}
function openNode($i,$j){//set nodes to open,if it is can open
global $rows;//get the rows
global $cols;//get the cols
global $data;//get the data
if($i < 0 || $i >= $rows || $j < 0 || $j >= $cols || $data["open".$i."_".$j])return;
//it is not a node,or it has been opened
$data["open".$i."_".$j] = 1;//open the node
if($data["data".$i."_".$j] > 0)return;//need to continue?
openNode($i - 1,$j - 1);
openNode($i - 1,$j);
openNode($i - 1,$j + 1);
openNode($i,$j - 1);
openNode($i,$j + 1);
openNode($i + 1,$j - 1);
openNode($i + 1,$j);
openNode($i + 1,$j + 1);
}
?>
扫雷游戏行数:
列数
雷数:
";
else if($checkflag == 2)echo "太挫了,又被雷炸死了
";
?>
" value="">
" value="">
')" style="width:20px;height:20px;">
希望本文所述对大家的php程序设计有所帮助。
本文原创发布php中文网,转载请注明出处,感谢您的尊重!