70 lines
1.2 KiB
PHP
70 lines
1.2 KiB
PHP
<?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();
|
|
break;
|
|
|
|
default:
|
|
exit('Invalid choice!');
|
|
|
|
}
|
|
|
|
|
|
switch ($computerChoice)
|
|
{
|
|
case 'rock':
|
|
|
|
$computerChoiceItem = new Rock();
|
|
break;
|
|
|
|
case 'paper':
|
|
$computerChoiceItem = new Paper();
|
|
break;
|
|
|
|
case 'scissors':
|
|
$computerChoiceItem = new Scissors();
|
|
break;
|
|
|
|
default:
|
|
exit('Internal error: Invalid computer choice.');
|
|
}
|
|
|
|
|
|
$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; |