16 Mai
This commit is contained in:
32
BACKEND/PHP/tp4/ex2/css/style.css
Normal file
32
BACKEND/PHP/tp4/ex2/css/style.css
Normal file
@@ -0,0 +1,32 @@
|
||||
table.morpion{
|
||||
border-collapse: collapse;
|
||||
table-layout:fixed;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
display:inline-block;
|
||||
width:auto;
|
||||
}
|
||||
table.morpion td {
|
||||
border : 1px solid #aaaaaa;
|
||||
width:10rem;
|
||||
height:10rem;
|
||||
padding : 0px;
|
||||
margin:0px;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-align:center;
|
||||
vertical-align:middle;
|
||||
}
|
||||
table.morpion i {
|
||||
font-size:8rem;
|
||||
}
|
||||
|
||||
table.morpion a {
|
||||
display : inline-block;
|
||||
width : 8rem;
|
||||
height: 8rem;
|
||||
|
||||
}
|
||||
.center{
|
||||
text-align:center;
|
||||
}
|
66
BACKEND/PHP/tp4/ex2/include/tictactoe.php
Normal file
66
BACKEND/PHP/tp4/ex2/include/tictactoe.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
$message = "";
|
||||
$grid = [0,1,0,1,0,2,2,0,0];
|
||||
|
||||
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
//
|
||||
|
||||
function isWinner($grid, $player)
|
||||
{
|
||||
$winStates = array
|
||||
(
|
||||
array(0, 1, 2), array(3, 4, 5), array(6, 7, 8), // Horizontal
|
||||
array(0, 3, 6), array(1, 4, 7), array(2, 5, 8), // Vertical
|
||||
array(0, 4, 8), array(2, 4, 6) // Diagonal
|
||||
);
|
||||
|
||||
foreach ($winStates as $winState)
|
||||
{
|
||||
if ($grid[$winState[0]] == $player &&
|
||||
$grid[$winState[1]] == $player &&
|
||||
$grid[$winState[2]] == $player)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function noWinner($grid)
|
||||
{
|
||||
for($i = 0; $i < 9; $i++)
|
||||
if ($grid[$i] == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function displayGrid($grid)
|
||||
{
|
||||
echo '<table class="morpion">';
|
||||
for ($i = 0; $i < 3; $i ++){
|
||||
echo "<tr>";
|
||||
for ($j = 0; $j < 3; $j ++){
|
||||
|
||||
echo "<td>";
|
||||
|
||||
$pos = 3*$i + $j;
|
||||
if ($grid[$pos] == 0)
|
||||
echo "<a href='?pos=$pos'></a>";
|
||||
if ($grid[$pos] == 1)
|
||||
echo '<i class="fa fa-times" aria-hidden="true"></i>';
|
||||
if ($grid[$pos] == 2)
|
||||
echo '<i class="fa fa-circle-o" aria-hidden="true"></i>';
|
||||
|
||||
echo "</td>";
|
||||
|
||||
}
|
||||
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
}
|
26
BACKEND/PHP/tp4/ex2/index.php
Normal file
26
BACKEND/PHP/tp4/ex2/index.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
include 'include/tictactoe.php';
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="stylesheet" href="https://unpkg.com/@picocss/pico@1.*/css/pico.min.css">
|
||||
<link rel="stylesheet" href="./css/style.css">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<main class="container center">
|
||||
<h3>Tic Tac Toe : <?php echo "player $playerTurn turn";?></h3>
|
||||
|
||||
<?php
|
||||
if ($message != ""){
|
||||
echo "<h1>$message";
|
||||
echo " <a href='?'>new game</a></h1>";
|
||||
}
|
||||
displayGrid($grid);
|
||||
?>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user