日期:2011-08-07  浏览次数:20545 次

我觉得用PHP+JS可以设计出挺牛逼的二维网页游戏,当然网络型的网页游戏后台数据的交互可以使用java来做数据处理。

\

 

<?php  
 
$init = $_POST["init"];//game restart  
$clickvalue = $_POST["clickvalue"];//minesweeping  
$checkflag = 0;//Victory or defeat  
$click_count = 0;//clicks count  
if($init == null && $clickvalue == null){//initialization  
    $_POST = array();//set POST with a array  
    $_POST["rows"] = 9;//set rows  
    $_POST["cols"] = 9;//set cols  
    $_POST["num"] = 10;//set num  
    $_POST["timeshow"] = "00:00"; //set starttime  
    $init = true;//set initialization  
}  
$rows = $_POST["rows"];//get rows  
$cols = $_POST["cols"];//get cols  
$num = $_POST["num"];//get num  
$starttime = $_POST["starttime"];//get starttime  
if($init){// is initialization  
    $timeshow = "00:00";//set starttime  
    $data = array();//data initialization  
    for($i=0;$i<$rows;$i++){//all the rows  
        for($j=0;$j<$cols;$j++){//all the cols  
            $data["data".$i."_".$j] = 0;//set mine with null  
            $data["open".$i."_".$j] = 0;//set node with close  
        }  
    }  
    $i=0;//reset the index,and set the mines(Random setting)  
    while($i < $num){//number of mine  
        $r = rand(0,$rows - 1);//row's index  
        $c = rand(0,$cols - 1);//col's index  
        if($data["data".$r."_".$c] == 0){//if not a mine  
            $data["data".$r."_".$c] = 100;//set the node with a mine  
            $i++;  
        }  
    }  
    for($i=0;$i<$rows;$i++){//all the rows  
        for($j=0;$j<$cols;$j++){//all the cols  
            if($data["data".$i."_".$j] == 100)continue;//is not a mine , set number of adjacent mines   
            $cnt = 0;  
            if($i - 1 >= 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++;//upp