Php-implemented online game example with scissors
This article describes the php-implemented online game with a stone scissors. We will share this with you for your reference. The details are as follows:
<? Php/** Created on **/if (isset ($ _ POST ['sub']) {$ what = $ _ POST ['wh']; // The array to be Input $ my_array = array ("Scissors", "Stone", "cloth"); // The winning rule $ guize = array ("Scissors ", "cloth"), array ("cloth", "Stone"), array ("Stone", "Scissors ")); // obtain the random value $ rand_keys = array_rand ($ my_array); $ computer = $ my_array [$ rand_keys]; echo "your ". $ what. "". $ computer. "<br/>"; $ input = array ($ computer, $ what); // constructs an array of the randomly generated values of the input and the computer, then, we can judge that I is not in the winning rule. F (! (In_array ($ what, $ my_array) {echo "Please input scissors, stones, cloth"; header ("location: index. php ");} if ($ computer = $ what) {echo" Oh, flat ";} elseif (in_array ($ input, $ guize )) {echo "Computer wins";} else {echo "You win ~ ";}}?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Run the following command: