diff --git a/R3.01/README.md b/R3.01/README.md index 1bb23c0..f336a95 100644 --- a/R3.01/README.md +++ b/R3.01/README.md @@ -32,6 +32,7 @@ Les notions suivantes seront abordées : | ------------------ | -------------------------------------------------------- | ------------------ | | 1 : 24/03 - 28/03| [Bases du langages](./cours/cm_bases_php.pdf) | [tp1](./tp/tp1) | | 2 : 03/04 - 07/04 | [Intéractions avec le client](./cours/cm_interaction_client_serveur.pdf) | [tp2](./tp/tp2) | +| 3 : 10/04 - 14/04 | [PHP/MySQL](./cours/cm_extension_mysqli.pdf) | [tp3](./tp/tp3) | ## Les TPS @@ -41,4 +42,17 @@ permet de se familiariser avec le langage PHP. À chaque exercice correspond un sous répertoire avec des fichiers à compléter. +#### TP2 : Intéractions avec le client, formulaires et PHP +Le [tp2](./tp/tp2) +aborde la récupération des données de formulaires avec PHP. +À chaque exercice correspond un sous répertoire avec +des fichiers à compléter. + +#### TP3 : PHP/Mysql +Le [tp3](./tp/tp3) +aborde l'interfaçage de php avec mysql, au moyen de l'extention +[mysqli](http://php.net/manual/fr/book.mysqli.php) de php. +À chaque exercice correspond un sous répertoire avec +des fichiers à compléter. + diff --git a/R3.01/tp/tp3/README.md b/R3.01/tp/tp3/README.md new file mode 100644 index 0000000..c6d71fa --- /dev/null +++ b/R3.01/tp/tp3/README.md @@ -0,0 +1,40 @@ +# TP 3 : Passage de paramètres à un script, PHP-MariaDB avec l'extension **mysqli**. + +> Le style utilisé dans les sources est [picocss](https://picocss.com/). + +### Ex1. +Le but est d'écrire un script php simulant le jeu de hasard pierre, +feuille ciseaux (encore appelé chifoumi). +<div align="center"> +<img src="./img/chifoumi.png"> +</div> + +Le joueur joue en cliquant sur l'icone représentant le coup qu'il +a choisi. Celui-ci est un lien vers le même script, auquel est passé +en GET un paramètre représentant son choix. Par exemple : + +```html +<a href="?choice=0"><img href="rock.png"></a> +<a href="?choice=1"><img href="paper.png"></a> +<a href="?choice=2"><img href="scissors.png"></a> +``` +Le script récupère le coup du joueur, fait un tirage aléatoire, et +affiche les deux coups joués avec un message pour indiquer le +résultat de la partie. + +Le code est organisé sommairement suivant le pattern `MVC`. Le script `index.php` fait office de contrôleur. +- il récupére le choix du joueur, +- il fait jouer l'ordinateur (tirage aléatoire), +- il calcule l'issue de la partie, +- il affiche (include) les différentes parties de la vue finale, avec les variables nécessaires. + +Remarque : pour éviter un code trop verbeux au niveau des tests pour calculer le résultat d'une partie, +vous pouvez utiliser un tableau pour représenter les règles du jeu. Par exemple, + +```php +<?php +// 0 rock, 1 paper, 2 scissors +$rules = [ 0 => [ 0 => "Draw", 1 => "Loss", 2 => "Win"], ... ]; +``` + + diff --git a/R3.01/tp/tp3/chifoumi/css/style.css b/R3.01/tp/tp3/chifoumi/css/style.css new file mode 100644 index 0000000..51fbf56 --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/css/style.css @@ -0,0 +1,10 @@ +.center{ + text-align:center; +} +.Win{ +color:#2E8B57; + +} +.Loss{ +color:#FF6347; +} diff --git a/R3.01/tp/tp3/chifoumi/images/ciseaux.png b/R3.01/tp/tp3/chifoumi/images/ciseaux.png new file mode 100644 index 0000000..6862730 Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/ciseaux.png differ diff --git a/R3.01/tp/tp3/chifoumi/images/feuille.png b/R3.01/tp/tp3/chifoumi/images/feuille.png new file mode 100644 index 0000000..80bca11 Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/feuille.png differ diff --git a/R3.01/tp/tp3/chifoumi/images/paper.png b/R3.01/tp/tp3/chifoumi/images/paper.png new file mode 100644 index 0000000..80bca11 Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/paper.png differ diff --git a/R3.01/tp/tp3/chifoumi/images/pierre.png b/R3.01/tp/tp3/chifoumi/images/pierre.png new file mode 100644 index 0000000..d19d50e Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/pierre.png differ diff --git a/R3.01/tp/tp3/chifoumi/images/rock.png b/R3.01/tp/tp3/chifoumi/images/rock.png new file mode 100644 index 0000000..d19d50e Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/rock.png differ diff --git a/R3.01/tp/tp3/chifoumi/images/scissors.png b/R3.01/tp/tp3/chifoumi/images/scissors.png new file mode 100644 index 0000000..6862730 Binary files /dev/null and b/R3.01/tp/tp3/chifoumi/images/scissors.png differ diff --git a/R3.01/tp/tp3/chifoumi/index.php b/R3.01/tp/tp3/chifoumi/index.php new file mode 100644 index 0000000..7845b33 --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/index.php @@ -0,0 +1,20 @@ +<?php +$images = ["rock.png","paper.png","scissors.png"]; +$isPlaying = true; + +$playerChoice = 0; +$computerChoice = 1; + +$message = "Win"; +$class = "Win"; + +$imagePlayer = $images[$playerChoice]; +$imageComputer = $images[$computerChoice]; + +include './views/header.php'; +if ($isPlaying){ + include './views/game.php'; + include './views/message.php'; +} +include './views/footer.php'; +?> diff --git a/R3.01/tp/tp3/chifoumi/views/footer.php b/R3.01/tp/tp3/chifoumi/views/footer.php new file mode 100644 index 0000000..a78654e --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/views/footer.php @@ -0,0 +1,3 @@ + </main> + </body> +</html> diff --git a/R3.01/tp/tp3/chifoumi/views/game.php b/R3.01/tp/tp3/chifoumi/views/game.php new file mode 100644 index 0000000..b1ee2e7 --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/views/game.php @@ -0,0 +1,15 @@ +<div class="grid"> + <article> + <header>Player</header> + <section class="center"> + <img src="./images/<?php echo $imagePlayer;?>"> + </section> + </article> + <article> + <header>Computer</header> + <section class="center"> + <img src="./images/<?php echo $imageComputer;?>"> + </section> + </article> +</div> + diff --git a/R3.01/tp/tp3/chifoumi/views/header.php b/R3.01/tp/tp3/chifoumi/views/header.php new file mode 100644 index 0000000..48266c9 --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/views/header.php @@ -0,0 +1,25 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="UTF-8" > +<link + rel="stylesheet" + href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" +/> + + <link rel="stylesheet" href="./css/style.css"> + <title>Chifoumi</title> + </head> + <body> + <main class="container"> + + <h3>Rock Paper Scissors</h3> + + <section class="center"> + <p>Choose : </p> + <a href="?choice=0"><img width="100px" src="./images/rock.png"></a> + <a href="?choice=1"><img width="100px" src="./images/paper.png"></a> + <a href="?choice=2"><img width="100px" src="./images/scissors.png"></a> + </section> + + diff --git a/R3.01/tp/tp3/chifoumi/views/message.php b/R3.01/tp/tp3/chifoumi/views/message.php new file mode 100644 index 0000000..b34df0d --- /dev/null +++ b/R3.01/tp/tp3/chifoumi/views/message.php @@ -0,0 +1,3 @@ +<h2 class="center"> + <span class="<?php echo $class;?>"><?php echo $message;?></span> +</h2> diff --git a/R3.01/tp/tp3/img/chifoumi.png b/R3.01/tp/tp3/img/chifoumi.png new file mode 100644 index 0000000..3240e58 Binary files /dev/null and b/R3.01/tp/tp3/img/chifoumi.png differ diff --git a/R3.01/tp/tp3/img/db.gif b/R3.01/tp/tp3/img/db.gif new file mode 100644 index 0000000..3976075 Binary files /dev/null and b/R3.01/tp/tp3/img/db.gif differ diff --git a/R3.01/tp/tp3/img/film.png b/R3.01/tp/tp3/img/film.png new file mode 100644 index 0000000..2334700 Binary files /dev/null and b/R3.01/tp/tp3/img/film.png differ diff --git a/R3.01/tp/tp3/img/film1.png b/R3.01/tp/tp3/img/film1.png new file mode 100644 index 0000000..5a1f78f Binary files /dev/null and b/R3.01/tp/tp3/img/film1.png differ diff --git a/R3.01/tp/tp3/img/film2.png b/R3.01/tp/tp3/img/film2.png new file mode 100644 index 0000000..a05988e Binary files /dev/null and b/R3.01/tp/tp3/img/film2.png differ diff --git a/R3.01/tp/tp3/img/film3.png b/R3.01/tp/tp3/img/film3.png new file mode 100644 index 0000000..a568902 Binary files /dev/null and b/R3.01/tp/tp3/img/film3.png differ