2020-02-18 14:47:34 +00:00
|
|
|
<?php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
|
|
|
|
use miguel456\rps\Core\Paper;
|
|
|
|
use miguel456\rps\Core\Rock;
|
|
|
|
use miguel456\rps\Core\Scissors;
|
|
|
|
|
|
|
|
|
|
|
|
$humanChoice = 'scissors';
|
|
|
|
$computerChoice = 'paper';
|
|
|
|
|
|
|
|
echo 'debug: ' . PHP_EOL;
|
|
|
|
|
|
|
|
echo 'human: ' . $humanChoice . PHP_EOL;
|
|
|
|
echo 'robot: ' . $computerChoice . PHP_EOL;
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
|
|
|
switch ($humanChoice)
|
|
|
|
{
|
|
|
|
case 'rock':
|
|
|
|
|
|
|
|
$humanChoiceItem = new Rock();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'paper':
|
|
|
|
$humanChoiceItem = new Paper();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'scissors':
|
|
|
|
$humanChoiceItem = new Scissors();
|
2020-02-18 16:07:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
exit('Invalid choice!');
|
|
|
|
|
2020-02-18 14:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch ($computerChoice)
|
|
|
|
{
|
|
|
|
case 'rock':
|
|
|
|
|
|
|
|
$computerChoiceItem = new Rock();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'paper':
|
|
|
|
$computerChoiceItem = new Paper();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'scissors':
|
|
|
|
$computerChoiceItem = new Scissors();
|
2020-02-18 16:07:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
exit('Internal error: Invalid computer choice.');
|
2020-02-18 14:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$result = $humanChoiceItem->evaluateMatch($computerChoiceItem);
|
|
|
|
|
|
|
|
if ($result['defeated'])
|
|
|
|
{
|
|
|
|
echo 'You lose! The computer chose ' .$computerChoiceItem->getName();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo 'You win! The computer chose ' . $computerChoiceItem->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo PHP_EOL;
|