Last active
January 1, 2020 14:46
-
-
Save YavorK/e3698ea960d406f2f7579a233d8e0708 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$combos = [ | |
'paper' => [ | |
'vs_rock' => 'wins', | |
'vs_scissors' => 'loses', | |
], | |
'rock' => [ | |
'vs_paper' => 'loses', | |
'vs_scissors' => 'wins', | |
], | |
'scissors' => [ | |
'vs_rock' => 'loses', | |
'vs_paper' => 'wins', | |
] | |
]; | |
function getRandom(){ | |
$random = mt_rand(1, 3); | |
if ($random == 1){ | |
return 'rock'; | |
} | |
if ($random == 2){ | |
return 'paper'; | |
} | |
if ($random == 3){ | |
return 'scissors'; | |
} | |
} | |
$player = getRandom(); | |
echo "Player chose $player. \n\r"; | |
$computer = getRandom(); | |
echo "Compter chose $computer. \n\r"; | |
if($player == $computer) { | |
echo "Player and Computer are even."; | |
} | |
echo "Player ". $combos[$player]['vs_'.$computer]." \n\r"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment