Files
web_2025/R3.01/tp/tp3/chifoumi/index.php
T

32 lines
825 B
PHP
Raw Normal View History

2026-04-08 08:49:36 +02:00
<?php
2026-04-08 16:10:35 +02:00
$images = ["rock.png", "paper.png", "scissors.png"];
$rules = [
0 => [0 => "Draw", 1 => "Loss", 2 => "Win"],
1 => [0 => "Win", 1 => "Draw", 2 => "Loss"],
2 => [0 => "Loss", 1 => "Win", 2 => "Draw"],
];
2026-04-08 08:49:36 +02:00
2026-04-08 16:10:35 +02:00
$playerChoice = filter_input(
INPUT_GET,
'choice',
FILTER_VALIDATE_INT,
['options' => ['min_range' => 0, 'max_range' => 2]]
);
2026-04-08 08:49:36 +02:00
2026-04-08 16:10:35 +02:00
$isPlaying = ($playerChoice !== null && $playerChoice !== false);
2026-04-08 08:49:36 +02:00
2026-04-08 16:10:35 +02:00
if ($isPlaying) {
$computerChoice = mt_rand(0, 2);
$message = $rules[$playerChoice][$computerChoice];
$class = $message;
$imagePlayer = $images[$playerChoice];
$imageComputer = $images[$computerChoice];
2026-04-08 08:49:36 +02:00
}
2026-04-08 16:10:35 +02:00
include_once './views/header.php';
if ($isPlaying) {
include_once './views/game.php';
include_once './views/message.php';
}
include_once './views/footer.php';