-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame.php
More file actions
41 lines (34 loc) · 959 Bytes
/
game.php
File metadata and controls
41 lines (34 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
if (isset($_POST['number_of_pairs'])) {
$numberOfPairs = (int)$_POST['number_of_pairs'];
if ($numberOfPairs >= 2 && $numberOfPairs <= 9) {
$cards = array();
for($i = 1; $i <= $numberOfPairs; $i++) {
array_push($cards, $i, $i);
}
shuffle($cards);
} else {
$params = array('error' => 'Wrong number of pairs!');
header('Location: index.php?' . http_build_query($params));
}
} else {
http_response_code(500);
exit;
}
?>
<!doctype html>
<html>
<?php include('views/head.php'); ?>
<body>
<div id="board">
<?php
for($i = 0; $i < count($cards); $i++) {
echo "<div class='card' data-value='" . $cards[$i] . "'>";
echo "<img src='assets/img/cards/" . $cards[$i] . ".png' class='card--front'>";
echo "<img src='assets/img/cards/back.png' class='card--back'>";
echo "</div>";
}
?>
</div>
</body>
</html>