Created
October 28, 2021 01:16
-
-
Save susanBuck/e933c5382ac6dfb25fc029ce0ad3d58d to your computer and use it in GitHub Desktop.
Example
This file contains 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 | |
$player_move = $_POST['userPick']; | |
$computer_move = ['Rock', 'Paper', 'Scissors'][rand(0, 2)]; | |
$win = check_moves($player_move, $computer_move); | |
function check_moves($player, $computer) | |
{ | |
# Define variabel to track the winner if any, otherwise it will be a tie! | |
$win = ''; | |
# Game Logic begins with check if their moves are equal, then it will be a 'tie' | |
if ($player == $computer) { | |
$win = 'Tied'; | |
} | |
# player move is 'Rock' and Computer move is 'Scissors' | |
elseif (($player == 'Rock') && ($computer == 'Scissors')) { | |
$win = 'Player'; | |
# player move is 'Rock' and Computer move is 'Paper' | |
} elseif (($player == 'Rock') && ($computer == 'Paper')) { | |
$win = 'Computer'; | |
# Player move is 'Scissors' and Computer move is 'Rock' | |
} elseif (($player == 'Scissors') && ($computer == 'Rock')) { | |
$win = 'Computer'; | |
# Player move is 'Scissors' and Computer move is 'Paper' | |
} elseif (($player == 'Scissors') && ($computer == 'Paper')) { | |
$win = 'Player'; | |
# Player move is 'Paper' and Computer move is 'Rock' | |
} elseif (($player == 'Paper') && ($computer == 'Rock')) { | |
$win = 'Player'; | |
# Player move is 'Paper' and Computer move is 'Scissors' | |
} elseif (($player == 'Paper') && ($computer == 'Scissors')) { | |
$win = 'Computer'; | |
} | |
return $win; | |
} | |
require 'index-view.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment