Ejemplo n.º 1
0
        private void SupprimerCombattantSurBoard(OtherCase othercase) // OK
        {
            int x = othercase.PositionX;
            int y = othercase.PositionY;

            labyrinthe.Board[x, y] = caseFactory.returnCase("libre", x, y, labyrinthe);
        }
Ejemplo n.º 2
0
 private void AjouterStackActionList()
 {
     while (true)
     {
         OtherCase  othr = listeCombattants[1];
         Combattant comb = (Combattant)othr.Content;
         labyrinthe.ActionList = comb.Stack;
     }
 }
Ejemplo n.º 3
0
        private void AjouterObjetAuCombattant(OtherCase othercase, int x, int y)
        {
            OtherCase  other      = (OtherCase)labyrinthe.Board[x, y];
            Objet      objet      = (Objet)other.Content;
            Combattant combattant = (Combattant)othercase.Content;
            int        val        = objet.Valeur + combattant.Objet.Valeur;

            combattant.Objet.Valeur = val;
        }
Ejemplo n.º 4
0
        private void AjoutPositionsSurQueue(OtherCase othercase)// après avoir bouger
        {
            int        x    = othercase.PositionX;
            int        y    = othercase.PositionY;
            Combattant comb = (Combattant)othercase.Content;

            int[] tab = { x, y };
            comb.Stack.Push(tab);
        }
Ejemplo n.º 5
0
        public void CombattreEnnemi(OtherCase othercase, int x, int y)
        {
            OtherCase  othercasecombattant = (OtherCase)labyrinthe.Board[x, y];
            Combattant combattantennemi    = (Combattant)othercasecombattant.Content;

            Combattant moncombattant = (Combattant)othercase.Content;

            //"moncombattant" attaque "combattantennemi"
            combattantennemi.PointDeVie -= moncombattant.Objet.Valeur;
        }
Ejemplo n.º 6
0
        private bool VerifCaseVisiteBas(OtherCase othercase)
        {
            Combattant combattant = (Combattant)othercase.Content;

            if (combattant.BoardVisite[othercase.PositionX + 1, othercase.PositionY])
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
        public bool VerifCaseContientEnnemi(OtherCase othercase, int x, int y)
        {
            OtherCase othr = (OtherCase)labyrinthe.Board[x, y];

            if (!labyrinthe.Board[x, y].Libre && othr.Content is Combattant)
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 8
0
        private void AjoutVisiteHistorique(OtherCase othercase)// après avoir bouger
        {
            int x = othercase.PositionX;
            int y = othercase.PositionY;

            //cast du "content" de othercase
            Combattant comb = (Combattant)othercase.Content;

            //add true in the boardvisite (historic)
            comb.BoardVisite[x, y] = true;
        }
Ejemplo n.º 9
0
 private void AjouterCombattantSurBoard(OtherCase othercase, int newX, int newY)
 {
     //modifcation des positions de othercase
     ModifierPositionOthercase(othercase, newX, newY);
     //ajouter nouvelle position dans queue
     AjoutPositionsSurQueue(othercase);
     //ajouter case visitée à true
     AjoutVisiteHistorique(othercase);
     //ajout sur le board du labyrinthe
     labyrinthe.Board[newX, newY] = othercase;
 }
Ejemplo n.º 10
0
 private bool VerifCaseContientObjet(int x, int y) // case à coté du combattant
 {
     if (labyrinthe.Board[x, y] is OtherCase)
     {
         OtherCase othr = (OtherCase)labyrinthe.Board[x, y];
         if (!labyrinthe.Board[x, y].Libre && othr.Content is Objet)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
        //l'othercase est déjà placé => récupère la position de othercase, add true (visite), add positions to the stack
        private void InitCombattantListVisitesAndQueue(OtherCase othercase) // OK
        {
            //récupérer la position de othercase
            int x = othercase.PositionX;
            int y = othercase.PositionY;

            //cast du "content" de othercase
            Combattant comb = (Combattant)othercase.Content;

            //add true in the boardvisite (historic)
            comb.BoardVisite[x, y] = true;
            //add the array containing the position x an y to the stack
            int[] tab2 = { x, y };
            comb.Stack.Push(tab2);
        }
Ejemplo n.º 12
0
        // display the board in the console
        public void displayBoard(int delais, bool activeStack)
        {
            while (true)
            {
                for (int i = 0; i < dimX; i++)
                {
                    for (int j = 0; j < dimY; j++)
                    {
                        // si mur ou sortie (classe à part) OU libre
                        if (board[i, j].GetType() == typeof(Mur) || board[i, j].GetType() == typeof(Sortie) || board[i, j].Element.ToString() == " ")
                        {
                            Console.Write(board[i, j].Element);
                            if (j == dimY - 1)
                            {
                                Console.Write('\n');
                            }
                        }
                        else
                        {
                            OtherCase oc = (OtherCase)board[i, j];
                            Console.Write(oc.Element);
                        }
                    }
                }


                if (activeStack)
                {
                    foreach (int[] item in actionList)
                    {
                        Console.Write(item[0] + " " + item[1]);
                        Console.Write(" || ");
                    }

                    Console.Write("\n");
                    Console.WriteLine(actionList.Count);
                }


                Thread.Sleep(delais);
                Console.SetCursorPosition(0, 0);
            }
        }
Ejemplo n.º 13
0
        private bool [] CaseDejaVisite(OtherCase othercase)
        {
            bool[] tab = { false, false, false, false }; // gauche, haut, droite, bas (pour l'ordre)

            if (VerifCaseVisiteGauche(othercase))
            {
                tab[0] = true;
            }
            if (VerifCaseVisiteHaut(othercase))
            {
                tab[1] = true;
            }
            if (VerifCaseVisiteDroite(othercase))
            {
                tab[2] = true;
            }
            if (VerifCaseVisiteBas(othercase))
            {
                tab[3] = true;
            }

            return(tab);
        }
Ejemplo n.º 14
0
        //random choice on the possibilities, return one possiblities (the choice) return a number 0,1,2,or 3
        private int Decisiondeplacement(OtherCase othercase)   // OK
        {
            bool [] tabPossible = DeplacementsPossibles(othercase.PositionX, othercase.PositionY);
            bool [] tabVisite   = CaseDejaVisite(othercase);

            List <int> list = new List <int>();

            for (int i = 0; i < tabPossible.Length; i++)
            {
                if (entierBloque != i && tabPossible[i] && !tabVisite[i])
                {
                    list.Add(i);
                }
            }
            int r = 4; // si la valeur reste à 4 alors bloqué !!!!

            if (list.Count != 0)
            {
                r = random.Next(0, list.Count);
                return(list[r]);
            }
            return(r);
        }
Ejemplo n.º 15
0
 private void ModifierPositionOthercase(OtherCase othercase, int newX, int newY)
 {
     othercase.PositionX = newX;
     othercase.PositionY = newY;
 }
Ejemplo n.º 16
0
        private void FunctionCombattant(OtherCase othercase)
        {
            //1 seul fois
            InitCombattantListVisitesAndQueue(othercase);
            //les positions que l'on va incrémenter à chaque fois
            int x = othercase.PositionX;
            int y = othercase.PositionY;

            entierBloque = -1;

            while (othercase.GetType().ToString() != "Sortie") // while case is not "Sortie" Case
            {
                int n = Decisiondeplacement(othercase);

                // l'idée c'est que si l'on se retrouve au bout de l'impasse on est dans le cas n = 4, on va ensuite reculer (sauf que maintenant n n'est plus egal à 4, on utilise alors entierBloque
                // tant que entierBloque = 4, on recule (stack.pop). La condition de sortie (entierbloque = -1) est appliquer lorsque le nombre de case non visité est > 1.


                // si totalement bloqué => 2 cas : soit impasse => on ne peut que revenir en arriere, soit intersection dans laquelle toutes les possiblites ont été tester (donc visitées)
                if (n == 4 || entierBloque == 4)
                {
                    entierBloque = 4;
                    // revenir sur nos pas tant qu'il n'y a pas de case (non visité, et libre)
                    //vérification   des cases non visitées
                    bool[] tab = CaseDejaVisite(othercase);
                    int    l   = 0;
                    foreach (bool item in tab)
                    {
                        if (!item)
                        {
                            l++;
                        }
                    }
                    Combattant comb = (Combattant)othercase.Content;
                    if (l < 1)
                    {
                        entierBloque = 4; // on change entier bloque

                        //suppression de othercase (avec combattant dans board de labyrinthe)
                        SupprimerCombattantSurBoard(othercase);
                        //delete the last position in the stack (the current position)
                        comb.Stack.Pop();
                        int[] positions = comb.Stack.Peek();
                        //modify the positions of the othercase
                        othercase.PositionX = positions[0];
                        othercase.PositionY = positions[1];
                        x = positions[0];
                        y = positions[1];

                        //réajouter sur board sur positions précédentes
                        labyrinthe.Board[othercase.PositionX, othercase.PositionY] = othercase;
                    }

                    else
                    {
                        entierBloque = -1;
                    }

                    if (comb.Stack.Count == 0)
                    {
                        entierBloque = -1;
                    }


                    n = Decisiondeplacement(othercase);
                }

                // si non bloqué => n = 0,1,2,3
                else
                {
                    //suppression de othercase (avec combattant dans board de labyrinthe)
                    SupprimerCombattantSurBoard(othercase);


                    switch (n)
                    {
                    case 0:     // gauche
                        if (VerifCaseContientObjet(x, y - 1))
                        {
                            AjouterObjetAuCombattant(othercase, x, y - 1);
                        }
                        if (VerifCaseContientEnnemi(othercase, x, y - 1))
                        {
                            //tant que un des 2 ennemis n'est pas mort (cad que othercase du combattant ou othercase d combattant ennemi existe)
                            //combattre
                            //thread de mort ....

                            CombattreEnnemi(othercase, x, y - 1);
                        }
                        AjouterCombattantSurBoard(othercase, x, y - 1);
                        entierBloque = 2;
                        y           -= 1;
                        break;

                    case 1:     // haut
                        if (VerifCaseContientObjet(x - 1, y))
                        {
                            AjouterObjetAuCombattant(othercase, x - 1, y);
                        }
                        if (VerifCaseContientEnnemi(othercase, x - 1, y))
                        {
                            CombattreEnnemi(othercase, x - 1, y);
                        }
                        AjouterCombattantSurBoard(othercase, x - 1, y);
                        entierBloque = 3;
                        x           -= 1;
                        break;

                    case 2:     // droite
                        if (VerifCaseContientObjet(x, y + 1))
                        {
                            AjouterObjetAuCombattant(othercase, x, y + 1);
                        }

                        if (VerifCaseContientEnnemi(othercase, x, y + 1))
                        {
                            CombattreEnnemi(othercase, x, y + 1);
                        }
                        AjouterCombattantSurBoard(othercase, x, y + 1);
                        entierBloque = 0;
                        y           += 1;
                        break;

                    case 3:     // bas
                        if (VerifCaseContientObjet(x + 1, y))
                        {
                            AjouterObjetAuCombattant(othercase, x + 1, y);
                        }
                        if (VerifCaseContientEnnemi(othercase, x + 1, y))
                        {
                            CombattreEnnemi(othercase, x + 1, y);
                        }
                        AjouterCombattantSurBoard(othercase, x + 1, y);
                        entierBloque = 1;
                        x           += 1;
                        break;

                    default:
                        break;
                    }
                }
                Thread.Sleep(delay);
            }
        }