public void jouerPartie(bool nouvellePartie, Aventurier joueur, string nomPartie)
        {
            #region demmarrage d'une nouvelle partie
            if (nouvellePartie)
            {
                //On recupere la position de l'aventurier dans la map
                string positionInitialAventurier;
                string[] infosPremierNiveau = m_InfosCartes[0][3].Split(';'); // la position est sur la 4eme ligne de la première map
                positionInitialAventurier = infosPremierNiveau[infosPremierNiveau.Length - 1];
                //la position dans la map de l'aventurier est toujours le dernier element de la map
                joueur = new Vivant.Aventurier(positionInitialAventurier);
            }
            #endregion
            #region chargement des états de la partie en memoire sur le Dur
            else
            {
                m_EtatsDesCoffres = null; m_EtatsDesPieces = null; m_EtatsDesTorches = null;
                string coffreDecrypte = Fonctions.decryptage(nomPartie + "\\coffres.sav"),
                       torcheDecrypte = Fonctions.decryptage(nomPartie + "\\torches.sav"),
                       pieceDecrypte  = Fonctions.decryptage(nomPartie + "\\pieces.sav") ;
                #region chargement coffre
                XmlSerializer xs = new XmlSerializer(typeof(List<List<Objets.Coffres>>));
                using (StreamReader sw = new StreamReader(coffreDecrypte))
                { m_EtatsDesCoffres = xs.Deserialize(sw) as List<List<Objets.Coffres>>; }
                #endregion
                #region chargement torche
                xs = new XmlSerializer(typeof(List<List<Objets.Torches>>));
                using (StreamReader sw = new StreamReader(torcheDecrypte))
                { m_EtatsDesTorches = xs.Deserialize(sw) as List<List<Objets.Torches>>; }
                #endregion
                #region chargement pieces
                xs = new XmlSerializer(typeof(List<List<Objets.Pieces>>));
                using (StreamReader sw = new StreamReader(pieceDecrypte))
                { m_EtatsDesPieces = xs.Deserialize(sw) as List<List<Objets.Pieces>>; }
                #endregion
                File.Delete(coffreDecrypte); File.Delete(torcheDecrypte); File.Delete(pieceDecrypte);
            }
            #endregion
            const int tailleMaxCarteX = 100, tailleMaxCarteY = 100;
            List<List<affichage>> affichageMap = new List<List<affichage>>();
            #region première initialisation de affichageMap totalement vide
            for (int i = 0; i < tailleMaxCarteX; i++)
            {
                affichageMap.Add(new List<affichage>());
                for (int j = 0; j < tailleMaxCarteY; j++)
                    affichageMap[i].Add(new affichage());
            }
            #endregion
            while (true)
            {
                // on affiche la map avec comme arguments :
                /*
                 *  l'état du joueur
                 *  l'états des torches
                 *  l'états des pîeces
                 *  */
                m_Cartes[joueur.PositionZ].afficheMap(ref joueur,
                                                      m_EtatsDesTorches[joueur.PositionZ],
                                                      m_EtatsDesPieces[joueur.PositionZ],
                                                      ref affichageMap);
                bool apparitionMonstre = false; // un monstre peut il apparaitre, est mis a true si deplacement
                ConsoleKeyInfo touchePresse = Console.ReadKey();
                switch (touchePresse.Key)
                {
                    #region reaction mouvement
                    #region aller a gauche
                    case ConsoleKey.LeftArrow:
                        if (m_Cartes[joueur.PositionZ].m_Map[joueur.PositionX][(joueur.PositionY - 1)].estAtteignable)
                        { joueur.PositionY--; }
                        apparitionMonstre = true;
                        break;
                    #endregion
                    #region aller a droite
                    case ConsoleKey.RightArrow:
                        if (m_Cartes[joueur.PositionZ].m_Map[joueur.PositionX][(joueur.PositionY + 1)].estAtteignable)
                        { joueur.PositionY++; }
                        apparitionMonstre = true;
                        break;
                    #endregion
                    #region aller en haut
                    case ConsoleKey.UpArrow:
                        if (m_Cartes[joueur.PositionZ].m_Map[(joueur.PositionX - 1)][joueur.PositionY].estAtteignable)
                        { joueur.PositionX--; }
                        apparitionMonstre = true;
                        break;
                    #endregion
                    #region aller en bas
                    case ConsoleKey.DownArrow:
                        if(m_Cartes[joueur.PositionZ].m_Map.Count > (joueur.PositionX+2)) // tant que le joueur ne sort pas de la map
                                                                                // c'est +2 a cause d'une ligne suplémentaire dans la variable
                            if (m_Cartes[joueur.PositionZ].m_Map[(joueur.PositionX + 1)][joueur.PositionY].estAtteignable)
                            { joueur.PositionX++; }
                        apparitionMonstre = true;
                        break;
                    #endregion
                    #region changer de niveau -C
                    case ConsoleKey.C:
                        TypeDeLieu caseSousJoueur = m_Cartes[joueur.PositionZ].m_Map[joueur.PositionX][joueur.PositionY].TypeDeLaCase;
                        if (caseSousJoueur.Equals(TypeDeLieu.EscalierDescandant))
                        {
                            joueur.PositionZ--;
                            affichageMap = new List<List<affichage>>();
                            #region réinitialisation de affichageMap
                            for (int i = 0; i < tailleMaxCarteX; i++)
                            {
                                affichageMap.Add(new List<affichage>());
                                for (int j = 0; j < tailleMaxCarteY; j++)
                                    affichageMap[i].Add(new affichage());
                            }
                            #endregion
                        }
                        else if (caseSousJoueur.Equals(TypeDeLieu.EscalierMontant))
                        {
                            joueur.PositionZ++;
                            affichageMap = new List<List<affichage>>();
                            #region réinitialisation de affichageMap
                            for (int i = 0; i < tailleMaxCarteX; i++)
                            {
                                affichageMap.Add(new List<affichage>());
                                for (int j = 0; j < tailleMaxCarteY; j++)
                                    affichageMap[i].Add(new affichage());
                            }
                            #endregion
                        }
                        break;
                    #endregion
                    #endregion

                    #region actions dans le monde
                    #region allumer une torche - A
                    case ConsoleKey.A:
                        // si une des cases autour est une torche et qu'elle est eteinte
                        // on allume la torche => on change son état et sa couleur
                        foreach (Torches torche in m_EtatsDesTorches[joueur.PositionZ])
                        {
                            if (!torche.estAllume)
                            {
                                if (joueur.PositionX + 1 == torche.posX && joueur.PositionY     == torche.posY ||
                                    joueur.PositionX - 1 == torche.posX && joueur.PositionY     == torche.posY ||
                                    joueur.PositionX     == torche.posX && joueur.PositionY + 1 == torche.posY ||
                                    joueur.PositionX     == torche.posX && joueur.PositionY - 1 == torche.posY   )
                                {
                                    torche.estAllume = true;
                                    torche.couleurTorche = ConsoleColor.Yellow;
                                    break; // on sort de la boucle puisqu'on a trouvé la bonne torche
                        }   }   }
                        //sinon rien ne se passe
                        break;
                    #endregion
                    #region rammaser un objet - R
                    case ConsoleKey.R:
                        switch (m_Cartes[joueur.PositionZ].m_Map[joueur.PositionX][joueur.PositionY].TypeDeLaCase)
                        {
                            case TypeDeLieu.Piece:
                                foreach (Pieces piece in m_EtatsDesPieces[joueur.PositionZ])
                                {
                                    if (joueur.PositionX == piece.posX && joueur.PositionY == piece.posY && !piece.estPrise)
                                    {
                                        piece.estPrise = true;
                                        joueur.NombreDePiece++;
                                        break; // on sort de la boucle puisqu'on a trouvé la bonne piece
                                    }
                                }
                                break;
                            default: // si ce n'est pas l'un des cas si dessus
                                break; // on ne fais rien du tout
                        }
                        break;
                    #endregion
                    #region ouvrir un coffre - O
                    case ConsoleKey.O:
                        foreach(Coffres coffre in m_EtatsDesCoffres[joueur.PositionZ])
                        {
                            // si un coffre est a proximite
                            if (joueur.PositionX + 1 == coffre.posX && joueur.PositionY == coffre.posY ||
                                        joueur.PositionX - 1 == coffre.posX && joueur.PositionY == coffre.posY ||
                                        joueur.PositionX == coffre.posX && joueur.PositionY + 1 == coffre.posY ||
                                        joueur.PositionX == coffre.posX && joueur.PositionY - 1 == coffre.posY)
                            {
                                coffre.ouvert = true;
                                foreach (Objet obj in coffre.m_Contient)
                                {
                                    switch (obj.typeDeLObjet)
                                    {
                                        case TypeDObjet.Piece:
                                            joueur.NombreDePiece++;
                                            break;
                                        case TypeDObjet.Parchemin:
                                            joueur.nouveauSort((Parchemin)obj);
                                            break;
                                        case TypeDObjet.PotionMana:
                                            joueur.ajouterElement(obj);
                                            break;
                                        case TypeDObjet.PotionVie:
                                            joueur.ajouterElement(obj);
                                            break;
                                }    }
                                Console.SetCursorPosition(25, 10); Console.WriteLine("+---------------+");
                                Console.SetCursorPosition(25, 11); Console.WriteLine("| Coffre ouvert |");
                                Console.SetCursorPosition(25, 12); Console.WriteLine("+---------------+");
                                break;
                        }    }
                        break;
                    #endregion
                    #region ouvrir l'inventaire - I
                    case ConsoleKey.I:
                        joueur.afficherInventaire();
                        #region réinitialisation de affichageMap du fait des affichages précédents
                        affichageMap = new List<List<affichage>>();
                        for (int i = 0; i < tailleMaxCarteX; i++)
                        {
                            affichageMap.Add(new List<affichage>());
                            for (int j = 0; j < tailleMaxCarteY; j++)
                                affichageMap[i].Add(new affichage());
                        }
                        #endregion
                        break;
                    #endregion
                    #region menu(retour sauvegarde chargemment quitter) - ECHAP
                    case ConsoleKey.Escape:
                        bool choixMenu = false;
                        int choix = 0;
                        #region choix de l'action dans le menu
                        while (!choixMenu)
                        {
                            const int nombreAction = 4;
                            string[] action = new string[nombreAction];
                            action[0] = "   Retour  "; 
                            action[1] = "Sauvegarder";
                            action[2] = "  Charger  ";
                            action[3] = "  Quitter  ";
                            Console.ForegroundColor = ConsoleColor.Gray;
                            #region affichage
                            Console.SetCursorPosition(25, 10); Console.Write("+-------------------------------------+");
                            Console.SetCursorPosition(25, 11); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 12); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 13); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 14); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 15); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 16); Console.Write("|                                     |");
                            Console.SetCursorPosition(25, 17); Console.Write("+-------------------------------------+");
                            for (int i = 0; i < nombreAction; i++)
                            {
                                Console.ForegroundColor = (choix == i ? ConsoleColor.White : ConsoleColor.Gray);
                                Console.SetCursorPosition(30, i + 12); Console.Write(String.Format("{0,11}", action[i]));
                            }
                            #endregion
                            ConsoleKeyInfo presse = Console.ReadKey();
                            #region reaction
                            switch (presse.Key)
                            {
                                case ConsoleKey.UpArrow:
                                    if (choix == 0) choix = nombreAction;
                                    choix--;
                                    break;
                                case ConsoleKey.DownArrow:
                                    choix++;
                                    if (choix == nombreAction) choix = 0;
                                    break;
                                case ConsoleKey.Enter: choixMenu = true; break;
                                default: break;
                            }
                            #endregion
                        }
                        #endregion
                        #region reaction au choix
                        switch (choix)
                        {
                            case 0: break; // on ne fais rien
                            case 1: // sauvegarde
                                joueur.sauvegarder(m_EtatsDesCoffres, m_EtatsDesTorches, m_EtatsDesPieces); 
                                break;
                            case 2: // chargement
                                if(Fonctions.confirmationSauvegarde())
                                    joueur.sauvegarder(m_EtatsDesCoffres, m_EtatsDesTorches, m_EtatsDesPieces);
                                string nomPart;
                                Partie part = new Partie();
                                part.jouerPartie(false, Program.chargement(out nomPart), nomPart);
                                break;
                            case 3: // quitter
                                if (Fonctions.confirmationSauvegarde())
                                    joueur.sauvegarder(m_EtatsDesCoffres, m_EtatsDesTorches, m_EtatsDesPieces);
                                System.Diagnostics.Process.GetCurrentProcess().Kill();
                                break;
                        }
                        #endregion
                        #region réinitialisation de affichageMap du fait des affichages précédents
                        affichageMap = new List<List<affichage>>();
                        for (int i = 0; i < tailleMaxCarteX; i++)
                        {
                            affichageMap.Add(new List<affichage>());
                            for (int j = 0; j < tailleMaxCarteY; j++)
                                affichageMap[i].Add(new affichage());
                        }
                        #endregion
                        break;
                    #endregion
                    #endregion
                    #region aide declanchement d'action
                    #region combat -D niv,lettre carractéristique du monstre
                    case ConsoleKey.D: // test combat
                        Console.SetCursorPosition(0, 40);
                        string monstre = Console.ReadLine();
                        joueur.combat(new Creature(Int32.Parse(monstre.Split(',')[0]),
                                                               monstre.Split(',')[1],
                                                   (double)0
                                      )            );
                        #region réinitialisation de affichageMap du fait des affichages précédents
                        affichageMap = new List<List<affichage>>();
                        for (int i = 0; i < tailleMaxCarteX; i++)
                        {
                            affichageMap.Add(new List<affichage>());
                            for (int j = 0; j < tailleMaxCarteY; j++)
                                affichageMap[i].Add(new affichage());
                        }
                        #endregion
                        break;
                    #endregion
                    #region pause -P
                    case ConsoleKey.P: // test pause
                        string duree = Console.ReadLine();
                        Temps.Temps.pause(Int32.Parse(duree));
                        break;
                    #endregion
                    #region gain XP -G
                    case ConsoleKey.G: // test de gain de  niveau
                        joueur.gagneNiveau(true);
                        #region réinitialisation de affichageMap du fait des affichages précédents
                        affichageMap = new List<List<affichage>>();
                        for (int i = 0; i < tailleMaxCarteX; i++)
                        {
                            affichageMap.Add(new List<affichage>());
                            for (int j = 0; j < tailleMaxCarteY; j++)
                                affichageMap[i].Add(new affichage());
                        }
                        #endregion
                        break;
                    #endregion
                    #region torches allumées -T
                    case ConsoleKey.T:
                        foreach (Torches tor in m_EtatsDesTorches[joueur.PositionZ])
                        {
                            if (!tor.estAllume)
                            {
                                tor.estAllume = true;
                                tor.couleurTorche = ConsoleColor.Yellow;
                                break;
                        }    }
                        break;
                    #endregion
                    #region ajouter sort -S boule de feu (niv20) -15 mana
                    case ConsoleKey.S:
                        joueur.m_Grimmoire.Add(new Magie.Sort(Magie.Sorts.BouleDeFeu, 15, 20));
                        break;
                    #endregion
                    #region ajouter objet -B
                    case ConsoleKey.B:
                        string objet = Console.ReadLine();
                        switch (objet)
                        {
                            case "poso":
                                joueur.m_Sac.Add(new PotionSoin(0,0,25));
                                break;
                            case "poma":
                                joueur.m_Sac.Add(new PotionMana(0, 0, 25));
                                break;
                            case "piece" :
                                joueur.NombreDePiece++; break;
                            default: break;
                        }
                        break;
                    #endregion
                    #endregion
                    default :
                        break;
                } // fin switch
                if (joueur.Mort)
                    break;

                #region determination d'un combat
                if (apparitionMonstre)
                {
                    Random nombre = new Random();
                    // calculer et effectuer la probabilité d'apparition des monstres puis voir si le monstre apparais
                    List<Creature> monstrePouvantAttaquer = new List<Creature>();
                    // pour chaque créature, si il peut apparaitre (réussite du if)
                    foreach (Creature monstre in m_CreaturesDansMaps[joueur.PositionZ])
                        if (monstre.FrequenceApparition > (double)(100 * nombre.NextDouble()))
                            monstrePouvantAttaquer.Add(monstre);
                    bool vraiAttaque = false; // pour vérifier si un monstre attaque réellement
                    Creature monstreAttaquant = new Creature() ;
                    foreach (Creature monstre in monstrePouvantAttaquer)
                        if (monstreAttaquant.FrequenceApparition < monstre.FrequenceApparition)
                        { monstreAttaquant = new Creature(monstre); vraiAttaque = true; } // on determine quel monstre attaque et on déclare une vrai attaque
                    
                    if (vraiAttaque) joueur.combat(monstreAttaquant);
                    // enfin a la fin du combat, du fait des affichages, on réinitialise affichageMap a totalement vide
                    #region réinitialisation de affichageMap
                    affichageMap = new List<List<affichage>>(); for (int i = 0; i < tailleMaxCarteX; i++)
                    {
                        affichageMap.Add(new List<affichage>());
                        for (int j = 0; j < tailleMaxCarteY; j++)
                            affichageMap[i].Add(new affichage());
                    }
                    #endregion
                }
                #endregion

            } // fin while(true)
        } // fin fonction
        public static Vivant.Aventurier chargement(out string nomPart)
        {
            bool suprimer = true;
            string repInit = Directory.GetCurrentDirectory();
            if (!Directory.Exists(repInit + "\\sav"))
                Directory.CreateDirectory(repInit + "\\sav");
            string[] listeRep;
            int choix, choixMax; bool choixFait = false; int nombreChoix;
            do
            {
                // on reactualise listeRep a chaque fois qu'on recommance la boucle
                listeRep = Directory.GetDirectories(repInit + "\\sav");
                for (int i = 0; i < listeRep.Length; i++)
                    listeRep[i] = listeRep[i].Split('\\')[listeRep[i].Split('\\').Length - 1];
                // reactualisation du nombre de choix
                choixMax = listeRep.Length; choix = 0; nombreChoix = choixMax + 3;
                while (!choixFait)
                {
                    #region affichage
                    Console.Clear();
                    Console.SetCursorPosition(20, 15); Console.WriteLine("+========CHARGEMENT========+");
                    Console.SetCursorPosition(20, 16); Console.WriteLine("|                          |");

                    for (int i = 0; i < choixMax; i++)
                    {
                        Console.SetCursorPosition(20, i + 17);
                        Console.Write("| ");
                        Console.ForegroundColor = (choix == i) ? ConsoleColor.White : ConsoleColor.Gray;
                        Console.Write(String.Format("{0,-24}", listeRep[i]));
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.Write(" |");
                    }
                    Console.SetCursorPosition(20, choixMax + 17); Console.WriteLine("|  CHARG        SUPPR      |");
                    Console.SetCursorPosition(20, choixMax + 18); Console.WriteLine("|        RETOUR            |");
                    Console.ForegroundColor = (choix == choixMax) ? ConsoleColor.Red : ConsoleColor.Gray;
                    Console.SetCursorPosition(29, choixMax + 18); Console.Write("RETOUR"); Console.ForegroundColor = ConsoleColor.Gray;
                    Console.SetCursorPosition(20, choixMax + 19); Console.WriteLine("+========CHARGEMENT========+");
                    #endregion

                    ConsoleKeyInfo presse = Console.ReadKey();

                    #region reaction touche
                    switch (presse.Key)
                    {
                        case ConsoleKey.UpArrow:
                            if (choix == 0) choix = choixMax + 1;
                            choix--;
                            break;
                        case ConsoleKey.DownArrow:
                            choix++;
                            if (choix > choixMax) choix = 0;
                            break;
                        case ConsoleKey.Enter:
                            choixFait = true;
                            bool choixSupprCharg = false;
                            if (choix == choixMax) throw new Exception(); // si il a fait retour, on lance une exception pour revenir au menu et recommencer le while
                            while (!choixSupprCharg)
                            {
                                #region affichage
                                Console.ForegroundColor = (!suprimer ? ConsoleColor.Red : ConsoleColor.White);
                                Console.SetCursorPosition(23, choixMax + 17); Console.Write("CHARG");
                                Console.ForegroundColor = (suprimer ? ConsoleColor.Red : ConsoleColor.White);
                                Console.SetCursorPosition(36, choixMax + 17); Console.Write("SUPPR");
                                #endregion
                                ConsoleKeyInfo touchePresse = Console.ReadKey();
                                #region reaction touche presse
                                switch (touchePresse.Key)
                                {
                                    //si supprimer est vrai, on le passe a faux, sinon on le passe a vrai
                                    case ConsoleKey.RightArrow: suprimer = !suprimer; break;
                                    case ConsoleKey.LeftArrow: suprimer = !suprimer; break;
                                    case ConsoleKey.Enter:
                                        choixSupprCharg = true;
                                        break;
                                    default: break;
                                }
                                #endregion
                            }
                            // le joueur a choisi entre supprimer et charger la partie
                            if (suprimer)
                            {
                                foreach (string fichier in Directory.GetFiles(repInit + "\\sav\\" + listeRep[choix]))
                                    File.Delete(fichier);
                                Directory.Delete(repInit + "\\sav\\" + listeRep[choix]);
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.BackgroundColor = ConsoleColor.White;
                                Console.SetCursorPosition(22, choixMax + 17); Console.Write("  Partie supprimee  ");
                                Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Gray;
                            }
                            break;
                        default: break;
                    }
                    #endregion
                }
                choixFait = false;
            } while (suprimer);// fin du while(supprimer) et du while(choixFais)
                #region reaction choix
                    nomPart = repInit + "\\sav\\" + listeRep[choix];
                    string cheminFichierDecrypte = Fonctions.decryptage(nomPart + "\\" + listeRep[choix] + ".sav");
                    XmlSerializer xs = new XmlSerializer(typeof(Vivant.Aventurier));
                    Vivant.Aventurier tmp = new Vivant.Aventurier();
                    using (StreamReader sr = new StreamReader(cheminFichierDecrypte))
                        tmp = xs.Deserialize(sr) as Vivant.Aventurier;

                    File.Delete(cheminFichierDecrypte);
                    return tmp;

                #endregion
        }