poche 发表于 2007-4-27 10:24:15

***游戏类***在线挖地雷游戏(根据ms改编)但必须在服务器上支持php运行的:(…

把下列代码加到网页的<body></body>标签之间 从google下载我的照片管理软件
<!--需要将些文件保存为 .php 文件!然后再在服务器上运行方可!-->
<?
    // phpmine v1.0
    //来源http://www.phpvault.com
    //是根据microsoft的挖地雷游戏编写
    print "<html>";
    print "<head>";
    print "<title>php挖地雷</title>";
    print "</head>";
    print "<body bgcolor=#ffffcc><center>";
    print "<font size=3 face=verdana><b>php挖地雷</b>";
    if ($submit=="")
    {
      $nummine=4;
      $rowsize=5;
      $colsize=5;
      $generer=1;
    }
    if($generer==1)
    {
      srand((double)microtime()*100000000);

      $time_start=time();
      //判断输入的数值是否正确
      if(($rowsize<=1) || ($colsize<=1) || ($nummine==0))
      {
            print "<p><br><font size=-1 color=red>行数,列数或地雷数输入错误!!</font>";
            exit;
      }
      if($nummine > $rowsize*$colsize)
      {
            print "<p><br><font size=-1 color=red>地雷数太多!</font>";
            exit;
      }
      //初始化
      for($row=1;$row<=$rowsize;$row++)
      {
            for($col=1;$col<=$colsize;$col++)
            {
                $mine[$row][$col]="0";
                $decouv[$row][$col]="0";
            }
      }
      $index=0;
      while($index<$nummine)
      {
            $row=rand(1,$rowsize);
            $col=rand(1,$colsize);
            if($mine[$row][$col]=="0")
            {
                $mine[$row][$col]="1";
                $index++;
            }
      }
    }
    else
    {
      $perdu=0;
      $reste=$rowsize*$colsize;
      for($row=1;$row<=$rowsize;$row++)
      {
            for($col=1;$col<=$colsize;$col++)
            {
                $temp="mine".($row*($colsize+1)+$col);
                $mine[$row][$col]=$$temp;
                $temp="decouv".($row*($colsize+1)+$col);
                $decouv[$row][$col]=$$temp;
                if($decouv[$row][$col]=="1") {$reste=$reste-1;}
                $temp="submit".($row*($colsize+1)+$col);
                if($$temp=="ok")
                {
                  $reste=$reste-1;
                  if($mine[$row][$col]=="0")
                  {
                        $decouv[$row][$col]="1";
                  }
                  else
                  {
                        $perdu=1;
                  }
                }
            }
      }
      if($perdu==1)
      {
            print "<h2><font color=red>您输啦!</font></h2>";
            for($i=1;$i<=$rowsize;$i++)
            {
                for($j=1;$j<=$colsize;$j++)
                {
                  $decouv[$i][$j]="1";
                }
            }
      }
      if(($reste==$nummine)&&($perdu!=1))
      {
            print "<h2>你赢啦!</h2>";
            $time_stop=time();
            $time=$time_stop-$time_start;
            print "<p><font size=-1><i>您的分数: $time</i></font>";
            for ($i=1;$i<=$rowsize;$i++)
            {
                for($j=1;$j<=$colsize;$j++)
                {
                  $decouv[$i][$j]="1";
                }
            }
      }
    }
    print "<form method=get action='$php_self'>";
    print "<input type=hidden name=time_start value=$time_start>";
    print "<input type=hidden name=nummine value=$nummine>";
    print "<input type=hidden name=rowsize value=$rowsize>";
    print "<input type=hidden name=colsize value=$colsize>";
    print "<input type=hidden name=generer value=0>";
    print "<p><table border=1 cellpadding=8>";
    for($row=1; $row<=$rowsize; $row++)
    {
      print "<tr>";
      for($col=1; $col<=$colsize; $col++)
      {
            $nb=0;
            for($i=-1; $i<=1; $i++)
            {
                for($j=-1; $j<=1; $j++)
                {
                  if($mine[$row+$i][$col+$j] == "1")
                  {
                        $nb++;
                  }
                }
            }
            print "<td width=15 height=15 align=center valign=middle>";
            if($decouv[$row][$col]=="1")
            {
                if($nb==0)
                {
                  print " ";
                }
                else
                {
                  if($mine[$row][$col]=="1")
                  {
                        print "<font color=red>*</font>";
                  }
                  else
                  {
                        print "$nb";
                  }
                }
            }
            else
            {
                print "<input type=hidden name=submit value=ok>";
                print "<input type=submit name=submit".($row*($colsize+1)+$col)." value=ok>";
            }
            print "<input type=hidden name=mine".($row*($colsize+1)+$col)." value=".$mine[$row][$col].">";
            print "<input type=hidden name=decouv".($row*($colsize+1)+$col)." value=".$decouv[$row][$col].">";
            print "</td>";
      }
      print "</tr>";
    }
    print "</table>";
    print "</form>";
?>
<hr>
<form method=post>
行数 :   
<input type=text name=rowsize value=5 size=2>
<br>
列数 :   
<input type=text name=colsize value=5 size=2>
<br>
地雷数 :   
<input type=text name=nummine value=4 size=2>
<p>
<input type=submit name=submit value=开始>
<input type=hidden name=generer value=1>
</form>
</body>
</html>
      










--------------------------------------

http://www.huoyue.com.cn 活跃网,活跃人群的论坛,访问活跃网,将给您带来意想不到的收获,还可以免费为您开论坛,让您免费拥有与朋友、网友交流的论坛。你是年轻人吗?你活跃你就上!
页: [1]
查看完整版本: ***游戏类***在线挖地雷游戏(根据ms改编)但必须在服务器上支持php运行的:(…