實(shí)例講述了php實(shí)現(xiàn)的網(wǎng)頁(yè)版剪刀石頭布攻略在玩游網(wǎng)上的設(shè)計(jì)。分享給大家供大家參考,具體如下:
?文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-582822.html
<?php
/*
* Created on 2016-11-25
*
*/
if (isset($_POST['sub'])) {
$what = $_POST['what'];
//需要輸入的數(shù)組
$my_array = array("剪刀","石頭","布");
//獲勝規(guī)則
$guize = array(array("剪刀","布"),array("布","石頭"),array("石頭","剪刀"));
//取數(shù)組中的隨機(jī)值
$rand_keys = array_rand($my_array);
$computer = $my_array[$rand_keys];
echo "你的".$what."VS ".$computer. "<br/>";
$input = array($computer,$what);
//將輸入的what和電腦隨機(jī)產(chǎn)生的值構(gòu)造成一個(gè)數(shù)組,再判斷在不在獲勝規(guī)則中
if (!(in_array($what,$my_array))) {
echo "請(qǐng)輸入 剪刀、石頭、布";
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="開(kāi)始!" />
<input type="reset" name="" value="重置" />
</p>
</form>
</body>
</html>文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-582822.html
到了這里,關(guān)于php做網(wǎng)頁(yè)版剪刀石頭布的功能的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!