From 3b051e3bff8c65de1cabfd9b96e420caea3dc354 Mon Sep 17 00:00:00 2001
From: ColinDrieu <colin.drieu@insa-rennes.fr>
Date: Mon, 21 Mar 2016 19:30:37 +0100
Subject: [PATCH] Ajout du fichier JoueurList.c avec le code de certaines
 fonctions

Code d'une partie de JoueurList.c
Correction de JoueurList.h
Correction de partie.h
---
 src/joueurList.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++
 src/joueurList.h |  11 +--
 src/partie.h     |   8 +-
 3 files changed, 198 insertions(+), 10 deletions(-)
 create mode 100644 src/joueurList.c

diff --git a/src/joueurList.c b/src/joueurList.c
new file mode 100644
index 0000000..27bf65b
--- /dev/null
+++ b/src/joueurList.c
@@ -0,0 +1,189 @@
+/*!
+* \file joueurList.c
+* \brief Fichier contenant le code des fonctions liees a la structure Partie.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "structures.h"
+#include "joueurList.h"
+
+/*!
+ * \fn NodeJoueur * initNodeJoueur(Joueur * j)
+ * \brief La fonction cree un nouveau NodeJoueur et initialise sa valeur courante.
+ *
+ * \param La fonction prend en entree un pointeur vers un Joueur.
+ * \return NULL si la valeur d'entree est nulle, un pointeur vers le NodeJoueur cree sinon.
+ */
+NodeJoueur * initNodeJoueur(Joueur * joueur){
+    if(joueur!=NULL){
+        NodeJoueur * nJ = malloc(sizeof(NodeJoueur));
+        nJ->j=joueur;
+        nJ->next=NULL;
+        return nJ;
+    }
+    return NULL;
+}
+
+/*!
+ * \fn void deleteNodeJoueur(NodeJoueur * j)
+ * \brief La fonction supprime un NodeJoueur et libere l'espace memoire qui lui etait alloue.
+ *
+ * \param La fonction prend en entree un pointeur vers un NodeJoueur.
+ */
+void deleteNodeJoueur(NodeJoueur * j){
+    if (j!=NULL){
+        free(j);
+    }
+}
+
+/*!
+ * \fn ListJoueur * initJoueurList(ListJoueur * l)
+ * \brief La fonction cree et initialise une ListJoueur.
+ *
+ * \return Un pointeur vers la ListJoueur cree et initialisee.
+ */
+ListJoueur * initJoueurList(){
+    ListJoueur * l = malloc(sizeof(ListJoueur));
+    l->firstNodeJoueur=NULL;
+    l->currentNodeJoueur=NULL;
+    l->lastNodeJoueur=NULL;
+    return l;
+}
+
+/*!
+ * \fn void deleteJoueurList(ListJoueur * l)
+ * \brief La fonction supprime une ListJoueur et libere l'espace alloue en memoire.
+ *        Attention, il faut egalement liberer les NodeJoueur appartement a la liste.
+ * \param Un pointeur vers la ListJoueur a supprimer.
+ */
+void deleteJoueurList(ListJoueur * l){
+    if(l!=NULL){
+        free(l);
+    }
+}
+
+// A DEFINIR, peut etre utile pour l'affichage en console.
+//void printJoueurList(ListJoueur * l);
+
+/*!
+ * \fn int emptyJoueurList(ListJoueur * l)
+ * \brief La fonction teste si la ListJoueur est vide.
+ *
+ * \param La ListJoueur a tester
+ * \return 1 si la liste est vide, 0 sinon
+ */
+int emptyJoueurList(ListJoueur * l){
+    if(l==NULL){
+        return 1;
+    }
+    if(l->firstNodeJoueur==NULL){
+        return 1;
+    }
+    return 0;
+}
+
+/*!
+ * \fn int outOfJoueurList(ListJoueur * l)
+ * \brief La fonction teste si le NodeJoueur courant est la dernier de la liste.
+ *
+ * \param La ListJoueur a tester
+ * \return 1 si le NodeJoueur courant est le dernier de la liste, 0 sinon
+ */
+int outOfJoueurList(ListJoueur * l){
+    if(!emptyJoueurList(l)){
+        if(l->currentNodeJoueur==l->lastNodeJoueur){
+            return 1;
+        }
+    }
+    return 0;
+}
+
+/*!
+ * \fn void setOnFirstJoueur(ListJoueur * l)
+ * \brief La fonction deplace le NodeJoueur courant sur le premier NodeJoueur de la liste.
+ *
+ * \param La ListJoueur a modifier.
+ */
+void setOnFirstJoueur(ListJoueur * l){
+    if(!emptyJoueurList(l)){
+        l->currentNodeJoueur=l->firstNodeJoueur;
+    }
+}
+
+/*!
+ * \fn void nextJoueur(ListJoueur * l)
+ * \brief La fonction deplace le NodeJoueur courant sur le NodeJoueur suivant.
+ *
+ * \param La ListJoueur a modifier.
+ */
+void nextJoueur(ListJoueur * l){
+    if(!emptyJoueurList(l)){
+        if(!outOfJoueurList(l)){
+            l->currentNodeJoueur=l->currentNodeJoueur->next;
+        }
+    }
+}
+
+/*!
+ * \fn Joueur * getCurrentJoueur(ListJoueur * l)
+ * \brief La fonction renvoie un pointeur vers le Joueur du NodeJoueur courant.
+ *
+ * \param La ListJoueur a tester.
+ * \return Un pointeur vers le Joueur du noeud courant, NULL si la liste est vide.
+ */
+Joueur * getCurrentJoueur(ListJoueur * l){
+    if(!emptyJoueurList(l)){
+        return l->currentNodeJoueur->j;
+    }
+    return NULL;
+}
+
+/*!
+ * \fn int addNodeJoueurFirst(ListJoueur * l, NodeJoueur * j)
+ * \brief La fonction ajoute un NodeJoueur au debut de la ListJoueur.
+ *
+ * \param La ListJoueur a modifier et un pointeur vers le NodeJoueur a ajouter.
+ * \return 1 si tout s'est bien passe, 0 sinon
+ */
+int addNodeJoueurFirst(ListJoueur * l, NodeJoueur * j){
+    if (j!=NULL){
+        if (l!=NULL){
+            if (emptyJoueurList(l)){
+                l->firstNodeJoueur=j;
+                return 1;
+            }
+            else{
+                j->next=l->firstNodeJoueur;
+                l->firstNodeJoueur=j;
+                return 1;
+            }
+        }
+    }
+    return 0;
+}
+
+/*!
+ * \fn int addNodeJoueurLast(ListJoueur * l, NodeJoueur * j)
+ * \brief La fonction ajoute un NodeJoueur en fin de la ListJoueur.
+ *
+ * \param La ListJoueur a modifier et un pointeur vers le NodeJoueur a ajouter.
+ * \return 1 si tout s'est bien passe, 0 sinon
+ */
+int addNodeJoueurLast(ListJoueur * l, NodeJoueur * j){
+    if(emptyJoueurList(l)){
+        return addNodeJoueurFirst(l,j);
+    }
+    else if(j!=NULL){
+        l->lastNodeJoueur->next=j;
+        l->lastNodeJoueur=j;
+        return 1;
+    }
+    return 0;
+}
+
+int deleteCurrentNodeJoueur(ListJoueur * l);
+
+void setOnJoueur(ListJoueur * l, Joueur * j);
+
+int deleteNodeJoueurFromList(ListJoueur * l, Joueur * j);
diff --git a/src/joueurList.h b/src/joueurList.h
index f21dda9..b5e36ce 100644
--- a/src/joueurList.h
+++ b/src/joueurList.h
@@ -9,11 +9,11 @@
 #include "structures.h"
 
 // Fonctions concernant la structure NodeJoueur
-NodeJoueur * initNodeJoueur(Joueur * j, NodeJoueur * n);
+NodeJoueur * initNodeJoueur(Joueur * joueur);
 void deleteNodeJoueur(NodeJoueur * j);
 
 // Fonctions concernant la structure ListJoueur
-void initJoueurList(ListJoueur * l);
+ListJoueur * initJoueurList();
 void deleteJoueurList(ListJoueur * l);
 
 void printJoueurList(ListJoueur * l);
@@ -23,13 +23,14 @@ int outOfJoueurList(ListJoueur * l);
 
 void setOnFirstJoueur(ListJoueur * l);
 void nextJoueur(ListJoueur * l);
-NodeJoueur * getCurrentJoueur(ListJoueur * l);
+Joueur * getCurrentJoueur(ListJoueur * l);
 
-int addNodeJoueurNext(ListJoueur * l, Joueur * j);
+int addNodeJoueurFirst(ListJoueur * l, NodeJoueur * j);
+int addNodeJoueurLast(ListJoueur * l, NodeJoueur * j);
 int deleteCurrentNodeJoueur(ListJoueur * l);
 
 void setOnJoueur(ListJoueur * l, Joueur * j);
 
-int deleteNodeJoueur(ListJoueur * l, Joueur * j);
+int deleteNodeJoueurFromList(ListJoueur * l, Joueur * j);
 
 #endif // JOUEUR_LIST_H
diff --git a/src/partie.h b/src/partie.h
index f091240..6e77922 100644
--- a/src/partie.h
+++ b/src/partie.h
@@ -5,6 +5,9 @@
 
 #include "structures.h"
 
+#ifndef PARTIE_H
+#define PARTIE_H
+
 Partie * initPartie();
 void deletePartie(Partie * p);
 
@@ -24,9 +27,4 @@ int victoire(Partie * p, Joueur * j);
 
 void finPartie(Partie * p);
 
-#ifndef PARTIE_H
-#define PARTIE_H
-
-
-
 #endif // PARTIE_H
-- 
GitLab