Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Computer Vs User Game [Rock, Sizor, Papper]!
- // Check the Argumets Number!
- if(count($argv) >= 3)
- die("Invalid Inputs!\n[!] The Script Excepts 1 parameter.\n");
- $AllowedCharacters = ['r', 'p', 's'];
- $UserInput = $argv[1];
- // Check the availability of the inputs.
- if(!in_array($UserInput, $AllowedCharacters))
- die("invalid Input!\n[!] {r} -> Rock, {p} -> Papper, {S} -> Sizor.\n");
- // Computer Random Output!
- // return: @string
- function CompyterPlay() {
- global $AllowedCharacters, $ArrayKey;
- $ArrayKey = mt_rand(0, 2);
- return $AllowedCharacters[$ArrayKey];
- }
- // Check the winner.
- if( $UserInput == 'r' && CompyterPlay() == 's'
- || $UserInput == 's' && CompyterPlay() == 'p'
- || $UserInput == 'p' && CompyterPlay() == 'r') {
- echo 'User Wins!';
- } else {
- echo 'Computer Wins!';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement