Home > php教程 > php手册 > php剪刀石头布编程思路,网页版

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:33:19
Original
1055 people have browsed it

在看了开源中国的网友发布的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>
Copy after login
<?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 "你赢咯~";
  			
  		}
  	
  }

 ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template