扫雷小游戏:
要求:实现扫雷,点某一个按钮,检测其上下左右,是不是雷,如果就炸掉,不是就标上Y
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function test(bom,x,y){
if(bom==1){
pass0=x+""+y;
if(y>1){
var pass1=x+""+y-1;
console.log(pass1);
}
if(y<10){
var pass2=x+""+Number(y+1);
console.log(pass2);
}
if(x>1){
var pass3=x-1+""+y;
console.log(pass3);
}
if(x<10){
var pass4=x+1+""+y;
console.log(pass4);
}
var arr=[pass0,pass1,pass2,pass3,pass4];
console.log(arr);
for(var i=0;i<=4;i++){
obj=document.getElementById("btn"+arr[i]);
tag=obj.getAttribute("tag");
if(tag==1){
obj.value="X"
}
tag==1?obj.value="X":obj.value="Y";
}
}
}
</script>
</head>
<body>
<?php
echo "<center><h1>我的扫雷游戏</h1><hr></center>";
echo "<table cellspacing=0 cellpadding=0 align=center>";
for($i=1;$i<=10;$i++){
echo "<tr>";
for($j=1;$j<=10;$j++){
echo "<td>";
$n=mt_rand(1,5000); //随机生成一个1-5000之间的数
if($n%2==0){
echo "<input type ='button' tag=1
id='btn".$i.$j."' value=' ' onclick='test(1,".$i.",".$j.");'>";
}else{
echo "<input type ='button' tag=0 value=' '
id='btn".$i.$j."' onclick='test(0,".$i.",".$j.");'>";
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
结果图:
扑克牌六张一行显示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.pk{
width: 60px;
height: 70px;
}
</style>
</head>
<body>
<table>
<?php
$d="";
$j=1;
for ($i=1; $i<=54; $i++) {
$d=$d."<td><img class='pk'"." src='./images02/".$i.".jpg'></td>";
if ($j%6==0) {
echo "<tr>";
echo $d;
echo "</tr>";
$d="";
$j=1;
}
else{
$j++;
}
}
?>
</table>
</body>
</html>
结果图:
编写一个函数,求任意两个数的四则运行算值:
<?php
function compute($a,$b,$op){
$c=0;
if($op=="+"){
$c=$a+$b;
}
if($op=="-"){
$c=$a-$b;
}
if($op=="*"){
$c=$a*$b;
}
if($op=="/"){
if($b==0){
$b=1;
}
$c=$a/$b;
}
return $c;
}
$x=50;
$y=100;
$z=compute($x,$y,"*");
echo "乘积是:".$z;
?>
结果图:
一百次我爱你:
<?php
echo "<hr>";
function saylove($n){
for($i=1;$i<=$n;$i++){
echo "<h3>I LOVE YOU</h3>";
}
}
saylove(100);
?>
结果图:
随机车牌程序:
<html>
<head>
<title></title>
<style type="text/css">
.cp{
font-size: 35px;
color: cornflowerblue;
height: 50px;
line-height: 50px;
text-align: center;
}
</style>
</head>
<body>
<?php
echo "<center><h1>交通车牌系统</h1></center>";
echo "<hr/>";
function cp(){
$x="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$y="";
for($i=1;$i<=5;$i++){
$n=mt_rand(0,strlen($x)-1);
$y=$y.substr($x,$n,1);
}
return $y="鄂A".$y;
}
function cptable($m,$n){
echo "<table border=1 width=100%>";
for($i=1;$i<=$m;$i++){
echo "<tr>";
for($j=1;$j<=$n;$j++){
echo "<td class='cp'>";
echo cp();
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
}
cptable(5,6);
?>
</body>
</html>
结果图: