实例讲述了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 "你的".$what."VS ".$computer. "
";
$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 "你赢咯~";
}
}
?>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
来源地址:https://blog.csdn.net/heiyefengdi/article/details/131782845