Home > Backend Development > PHP Tutorial > PHP rock paper scissors programming ideas, web version

PHP rock paper scissors programming ideas, web version

WBOY
Release: 2016-07-25 08:48:42
Original
1706 people have browsed it
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.
  1. Guess the Love
  2. Rock, paper, scissors, what did you come up with? * Rock, Paper, Scissors
  3. < /body>
Copy code
  1. if (isset($_POST['sub'])) {
  2. $what = $_POST['what'];
  3. //Array to be input
  4. $my_array = array( "Scissors","Rock","Paper");
  5. //Winning Rules
  6. $guize = array(array("Scissors","Paper"),array("Paper","Stone"),array(" Rock","Scissors"));
  7. //Get random values ​​from the array
  8. $rand_keys = array_rand($my_array);
  9. $computer = $my_array[$rand_keys];
  10. echo $computer. "n";
  11. $input = array($computer,$what);
  12. //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
  13. if (!(in_array($what ,$my_array))) {
  14. echo "Please enter scissors, rock, paper";
  15. header("location:index.php");
  16. }
  17. if ($computer == $what) {
  18. echo "Oh, Tie";
  19. }elseif (in_array($input,$guize)) {
  20. echo "The computer wins";
  21. }else {
  22. echo "You win~";
  23. }
  24. }
  25. ?>
Copy code


source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template