Advertisement
Guest User

Rock, Papper, Sizor game!

a guest
Apr 29th, 2018
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.81 KB | None | 0 0
  1. <?php
  2.  
  3. // Computer Vs User Game [Rock, Sizor, Papper]!
  4.  
  5. // Check the Argumets Number!
  6. if(count($argv) >= 3)
  7.     die("Invalid Inputs!\n[!] The Script Excepts 1 parameter.\n");
  8.  
  9. $AllowedCharacters = ['r', 'p', 's'];
  10. $UserInput = $argv[1];
  11.  
  12. // Check the availability of the inputs.
  13. if(!in_array($UserInput, $AllowedCharacters))
  14.     die("invalid Input!\n[!] {r} -> Rock, {p} -> Papper, {S} -> Sizor.\n");
  15.  
  16. // Computer Random Output!
  17. // return: @string
  18. function CompyterPlay() {
  19.     global $AllowedCharacters, $ArrayKey;
  20.     $ArrayKey = mt_rand(0, 2);
  21.     return $AllowedCharacters[$ArrayKey];
  22. }
  23.  
  24. // Check the winner.
  25. if(     $UserInput == 'r' && CompyterPlay() == 's'
  26.     ||  $UserInput == 's' && CompyterPlay() == 'p'
  27.     ||  $UserInput == 'p' && CompyterPlay() == 'r') {
  28.     echo 'User Wins!';
  29. } else {
  30.     echo 'Computer Wins!';
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement