After reading the shell version released by netizens of Open Source China, I tried to try it out. I hope you will not hesitate to let me know if there are any shortcomings.
- if (isset($_POST['sub'])) {
- $what = $_POST['what'];
-
- //Array to be input
- $my_array = array( "Scissors","Rock","Paper");
-
- //Winning Rules
- $guize = array(array("Scissors","Paper"),array("Paper","Stone"),array(" Rock","Scissors"));
-
- //Get random values from the array
- $rand_keys = array_rand($my_array);
- $computer = $my_array[$rand_keys];
-
- echo $computer. "n";
-
-
- $input = array($computer,$what);
- //Construct the input what and the value randomly generated by the computer into an array, and then determine whether it is within the winning rule
-
- if (!(in_array($what ,$my_array))) {
- echo "Please enter scissors, rock, paper";
- header("location:index.php");
- }
-
- if ($computer == $what) {
- echo "Oh, Tie";
- }elseif (in_array($input,$guize)) {
- echo "The computer wins";
- }else {
- echo "You win~";
-
- }
-
- }
- ?>
Copy code
|