欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

用php做扫雷游戏

程序员文章站 2022-04-14 13:16:52
...

php其实不适合做游戏,但是简单的游戏还是可以实现的,下面用php 实现简单的扫雷游戏,包含注释,代码只有167行 ?php$init = $_POST[init];//game restart$clickvalue = $_POST[clickvalue];//minesweeping$checkflag = 0;//Victory or defeat$click_count =

php其实不适合做游戏,但是简单的游戏还是可以实现的,下面用php 实现简单的扫雷游戏,包含注释,代码只有167行

= 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 = 0 && $data["data".$i."_".($j - 1)] == 100)$cnt++;//upper
			if($j + 1 = 0 && $data["data".($i + 1)."_".($j - 1)] == 100)$cnt++;//upper right
			if($i + 1 9?$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 = $rows || $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);
}
?>


minesweeper
rows:
cols
num:
"; else if($checkflag == 2)echo "game over!
"; ?>
" value=""> " value=""> ')" style="width:20px;height:20px;">



演示地址

http://www.fsanguo.comoj.com/public/minesweeper/index.php