首頁 > php教程 > php手册 > 主體

php剪刀石头布编程思路,网页版

WBOY
發布: 2016-06-06 19:33:19
原創
988 人瀏覽過

在看了开源中国的网友发布的shell版,于是乎也企图小试牛刀。有不足的地方希望各位不吝啬知道 无 html meta http-equiv="content-type" content="text/html" / head title猜情寻/title /head body form method="post" action="play.php" div align="center"剪

在看了开源中国的网友发布的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>
登入後複製
<?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 "你赢咯~";
  			
  		}
  	
  }

 ?>
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!