61 lines
1.0 KiB
PHP
61 lines
1.0 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();
|
|
}
|
|
|
|
|
|
switch ($computerChoice)
|
|
{
|
|
case 'rock':
|
|
|
|
$computerChoiceItem = new Rock();
|
|
break;
|
|
|
|
case 'paper':
|
|
$computerChoiceItem = new Paper();
|
|
break;
|
|
|
|
case 'scissors':
|
|
$computerChoiceItem = new Scissors();
|
|
}
|
|
|
|
|
|
$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; |