php剪刀石头布编程思路,网页版
在看了开源中国的网友发布的shell版,于是乎也企图小试牛刀。有不足的地方希望各位不吝啬知道
在看了开源中国的网友发布的shell版,于是乎也企图小试牛刀。有不足的地方希望各位不吝啬知道
<html>
<meta http-equiv="content-type" content="text/html" />
<head>
<title>猜情寻</title>
</head>
<body>
<form method="post" action="play.php">
<div align="center">剪刀石头布,你出什么?<input type="text" name="what" value="" />* 剪刀、石头、布</div>
<p align="center"><input type="submit" name="sub" value="开始!" /><input type="reset" name="" value="重置" /></p>
</form>
</body>
</html>
2. [代码][PHP]代码 跳至 [1] [2] [全屏预览]
<?php
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 $computer. "\n";
$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 "你赢咯~";
}
}
?>
- 上一篇:通用cms转换淘宝客
- 下一篇:PHP去除回车换行的三种方法
精彩图集
精彩文章






