Slide 135
Slide 135 text
function judge(int $leftHand, int $rightHand)
{
if ($leftHand === 0) { // Goo
if ($rightHand === 0) { // Goo
return 0;
} else if ($rightHand === 1) { // Choki
return 1;
} else { //Par
return -1;
}
} else if ($leftHand === 1) { // Choki
if ($rightHand === 0) { // Goo
return -1;
} else if ($rightHand === 1) { // Choki
return 0;
} else { //Par
return 1;
}
} else { // Par
if ($rightHand === 2) { // Goo
return 1;
} else if ($rightHand === 1) { // Choki
return -1;
} else { //Par
return 0;
}
}
}
}
class JankenGame
{
function play(int $leftHand, int $rightHand, string $lang)
{
$result = $this->judge($leftHand, $rightHand);
$this->showResult($result, $lang);
}
function showResult(int $result, string $lang)
{
if ($lang === "ja") {
if ($result === 1) {
echo "勝利";
} else if ($result === 0) {
echo "引き分け";
} else {
echo "敗北";
}
} else {
if ($result === 1) {
echo "win";
} else if ($result === 0) {
echo "draw";
} else {
echo "lose";
}
}
}