php實現的網頁版剪刀石頭布遊戲

來源:互聯網
上載者:User
這篇文章主要介紹了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"> <p align="center">剪刀石頭布,你出什嗎?<br/> <input type="radio" name="what" value="剪刀"/>剪刀<br/> <input type="radio" name="what" value="石頭"/>石頭<br/> <input type="radio" name="what" value="布"/>布<br/> </p> <p align="center"> <input type="submit" name="sub" value="開始!" /> <input type="reset" name="" value="重設" /> </p> </form></body></html>

運行如下:

以上就是本文的全部內容,希望對大家的學習有所協助。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.