Files
web_2025/R3.01/tp/tp3/chifoumi/index.php
T
JARNOUEN DE VILLARTAY Ulysse (SAFRAN AIRCRAFT ENGINES) 1dcd20de85 use constants for rock paper scissors
2026-04-08 17:13:19 +02:00

36 lines
932 B
PHP

<?php
$ROCK = 0;
$PAPER = 1;
$SCISSORS = 2;
$images = ["rock.png", "paper.png", "scissors.png"];
$rules = [
$ROCK => [$ROCK => "Draw", $PAPER => "Loss", $SCISSORS => "Win"],
$PAPER => [$ROCK => "Win", $PAPER => "Draw", $SCISSORS => "Loss"],
$SCISSORS => [$ROCK => "Loss", $PAPER => "Win", $SCISSORS => "Draw"],
];
$playerChoice = filter_input(
INPUT_GET,
'choice',
FILTER_VALIDATE_INT,
['options' => ['min_range' => 0, 'max_range' => 2]]
);
$isPlaying = ($playerChoice !== null && $playerChoice !== false);
if ($isPlaying) {
$computerChoice = mt_rand(0, 2);
$message = $rules[$playerChoice][$computerChoice];
$class = $message;
$imagePlayer = $images[$playerChoice];
$imageComputer = $images[$computerChoice];
}
include_once './views/header.php';
if ($isPlaying) {
include_once './views/game.php';
include_once './views/message.php';
}
include_once './views/footer.php';