实例讲述了php实现的网页版剪刀石头布攻略在玩游网上的设计。分享给大家供大家参考,具体如下:
文章来源:https://www.toymoban.com/news/detail-582822.html
<?php
/*
* Created on 2016-11-25
*
*/
if (isset($_POST['sub'])) {
$what = $_POST['what'];
//需要输入的数组
$my_array = array("剪刀","石头","布");
//获胜规则
$guize = array(array("剪刀","布"),array("布","石头"),array("石头","剪刀"));
//取数组中的随机值
$rand_keys = array_rand($my_array);
$computer = $my_array[$rand_keys];
echo "你的".$what."VS ".$computer. "<br/>";
$input = array($computer,$what);
//将输入的what和电脑随机产生的值构造成一个数组,再判断在不在获胜规则中
if (!(in_array($what,$my_array))) {
echo "请输入 剪刀、石头、布";
header("location:index.php");
}
if ($computer == $what) {
echo "噢,平手";
}elseif (in_array($input,$guize)) {
echo "电脑胜";
}else {
echo "你赢咯~";
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>剪刀石头布</title>
</head>
<body>
<form action="" method="post">
<div align="center">剪刀石头布,你出什么?<br/>
<input type="radio" name="what" value="剪刀"/>剪刀<br/>
<input type="radio" name="what" value="石头"/>石头<br/>
<input type="radio" name="what" value="布"/>布<br/>
</div>
<p align="center">
<input type="submit" name="sub" value="开始!" />
<input type="reset" name="" value="重置" />
</p>
</form>
</body>
</html>文章来源地址https://www.toymoban.com/news/detail-582822.html
到了这里,关于php做网页版剪刀石头布的功能的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!