rps/test.php

61 lines
1.0 KiB
PHP
Raw Normal View History

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();
}
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;