源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

php实现的网页版剪刀石头布游戏示例

  • 时间:2020-04-21 19:17 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:php实现的网页版剪刀石头布游戏示例
本文实例讲述了php实现的网页版剪刀石头布游戏。分享给大家供大家参考,具体如下:
<?php
/*
 * Created on 2016-11-25
 *
 */
 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. "<br/>";
    $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 "你赢咯~";
    }
 }
?>
<!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="开始!" />
 <input type="reset" name="" value="重置" />
 </p>
 </form>
</body>
</html>

运行效果图如下: [img]http://files.jb51.net/file_images/article/201611/2016112595037431.png?2016102595053[/img] 更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/614.htm]PHP数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/111.htm]php程序设计算法总结[/url]》、《[url=http://www.1sucai.cn/Special/630.htm]PHP数学运算技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/150.htm]php排序算法总结[/url]》、《[url=http://www.1sucai.cn/Special/242.htm]PHP常用遍历算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/180.htm]php正则表达式用法总结[/url]》、《[url=http://www.1sucai.cn/Special/357.htm]PHP运算与运算符用法总结[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部