From 533831b9c386af122bd10361e1a104775171bbe2 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 18 Apr 2024 15:28:10 +0200 Subject: [PATCH] osekour --- controleurs/jouerPartie_controleur.php | 42 ++++++++++++++----- vues/creerPartie_vue.php | 8 +++- vues/jouerPartie_vue.php | 58 +++++++++++++++++++------- 3 files changed, 82 insertions(+), 26 deletions(-) diff --git a/controleurs/jouerPartie_controleur.php b/controleurs/jouerPartie_controleur.php index 82a204f..38cb595 100644 --- a/controleurs/jouerPartie_controleur.php +++ b/controleurs/jouerPartie_controleur.php @@ -5,20 +5,36 @@ function getJoueursPartie(int $idpartie) return get_infos_requete("SELECT * FROM joue JOIN joueur J USING(idjoueur) WHERE joue.idpartie = " . $idpartie . " ORDER BY rang")['instances']; } -function getCardsName(int $idpartie) +function getJoueursPosition(int $idpartie, int $tour, int $pos) { - $cartes = get_infos_requete("SELECT img FROM carte JOIN est_compose USING(idcarte) JOIN partie USING(idplateau) WHERE idpartie = " . $idpartie . " ORDER BY rang")['instances']; - - $noms = array(); - foreach ($cartes as $carte) { - array_push($noms, $carte['img']); - } - - return $noms; + return get_infos_requete("SELECT idjoueur FROM est_en_position WHERE idpartie = " + . $idpartie . " AND position = " . $pos . " AND num_tour = " . $tour)['instances']; } -function get_parties_id() { - $parties = get_infos_requete("SELECT idpartie FROM partie")['instances']; +function partie_est_a_venir(int $idpartie) { + return !empty(get_infos_requete("SELECT idpartie FROM partie WHERE idpartie = " . + $idpartie . " AND etat = 'a venir'")['instances']); +} + +function get_parties_tour(int $idpartie): int { + $tour = get_infos_requete("SELECT * FROM tour WHERE idpartie = " + . $idpartie . " ORDER BY num_tour DESC LIMIT 1")['instances']; + + if (empty($tour)){ + return 0; + } + + return $tour[0]['num_tour']; +} + +function getCards(int $idpartie) +{ + return get_infos_requete("SELECT img, idcarte FROM carte JOIN est_compose USING(idcarte) JOIN partie USING(idplateau) WHERE idpartie = " . $idpartie . " ORDER BY rang")['instances']; +} + +function get_parties_id() +{ + $parties = get_infos_requete("SELECT idpartie FROM partie WHERE etat = 'a venir'")['instances']; $ids = array(); foreach ($parties as $partie) { @@ -28,4 +44,8 @@ function get_parties_id() { return $ids; } +function lancer_partie(int $idpartie) { + executer_une_requete("UPDATE partie SET etat = 'en cours' WHERE idpartie = " . $idpartie); +} + ?> \ No newline at end of file diff --git a/vues/creerPartie_vue.php b/vues/creerPartie_vue.php index 16ca38e..6916db7 100644 --- a/vues/creerPartie_vue.php +++ b/vues/creerPartie_vue.php @@ -66,6 +66,10 @@ function afficher_joueurs(int $idpartie) function formulaire_ajout_joueurs(int $idpartie) { + $joueursPartie = getJoueursPartie($idpartie); + if (sizeof($joueursPartie) >= 8) { + return; + } $joueurs = getJoueurs(); echo '
'; echo ''; - echo ''; + if (sizeof(getJoueursPartie($idpartie)) >= 2) { + echo ''; + } echo ''; echo '
'; } diff --git a/vues/jouerPartie_vue.php b/vues/jouerPartie_vue.php index 438eb06..c955676 100644 --- a/vues/jouerPartie_vue.php +++ b/vues/jouerPartie_vue.php @@ -1,5 +1,12 @@ '; + } +} + function afficher_joueurs(int $idpartie) { $joueurs = getJoueursPartie($idpartie); @@ -16,36 +23,44 @@ function afficher_joueurs(int $idpartie) echo ''; } -function afficherCarte(string $nomcarte, int $numero): void +function afficherCarte(string $nomcarte, int $numero, $joueurs): void { echo '
'; echo '' . $nomcarte . ''; - if ($numero != 0) { + if ($numero != 0 && $numero != 13) { echo '

' . $numero . '

'; } else { echo '

X

'; } + afficher_pions($joueurs); echo '
'; } -function afficher_depart(): void +function afficher_depart($joueurs): void { - afficherCarte("carteDépart.png", 0); + afficherCarte("carteDépart.png", 0, $joueurs); } function afficher_arrivee(): void { - afficherCarte("carteArrivée.png", 0); + afficherCarte("carteArrivée.png", 13, []); } -function afficherCartes(int $idpartie): void +function afficherCartes(int $idpartie, int $tour): void { - $cartes = getCardsName($idpartie); + $cartes = getCards($idpartie); echo '
'; - afficher_depart(); - for ($i = 0; $i < sizeof($cartes); $i++) { - afficherCarte($cartes[$i], $i + 1); + if ($tour == 0) { + afficher_depart(getJoueursPartie($idpartie)); + for ($i = 0; $i < sizeof($cartes); $i++) { + afficherCarte($cartes[$i]['img'], $i + 1, []); + } + } else { + afficher_depart(getJoueursPosition($idpartie, $tour, 0)); + for ($i = 0; $i < sizeof($cartes); $i++) { + afficherCarte($cartes[$i]['img'], $i + 1, []); + } } afficher_arrivee(); echo '
'; @@ -64,9 +79,16 @@ function formulaire_selection_partie() echo ''; } -function formulaire_selection_des_main() +function formulaire_lancer_partie(int $idpartie) { + echo '
'; + echo ''; + echo ''; + echo '
'; +} + +function formulaire_selection_des_main(int $idpartie) { - echo '
+ echo '
@@ -80,6 +102,7 @@ function formulaire_selection_des_main()
+
'; } @@ -95,13 +118,20 @@ function formulaire_selection_des_main() if (isset($_POST['idpartie'])) { $idpartie = (int) $_POST['idpartie']; + if (isset($_POST['lancerPartie'])) { + lancer_partie($idpartie); + } afficher_joueurs($idpartie); - afficherCartes($idpartie); + afficherCartes($idpartie, get_parties_tour($idpartie)); + if (partie_est_a_venir($idpartie)) { + formulaire_lancer_partie($idpartie); + } else { + formulaire_selection_des_main($idpartie); + } } else { formulaire_selection_partie(); } - formulaire_selection_des_main(); ?>