Exemple #1
0
        public bool Equals(Coordonnée coor)
        {
            if ((object)coor == null)
            {
                return(false);
            }

            return((getX() == (coor.getX())) && (getY() == (coor.getY())));
        }
Exemple #2
0
 public bool Equals(Coordonnée coor)
 {
     if ((object)coor == null)
     {
         return false;
     }
     
     return (getX() == (coor.getX())) && (getY() == (coor.getY()));
 }
Exemple #3
0
        private void BoardSetup(int sizeMap)
        {
            boardHolder = new GameObject("Board").transform;

            Map maze = Map.creerLabyrinthe(sizeMap, sizeMap);

            GameObject instance;

            Coordonnée coorDepart = new Coordonnée();
            Coordonnée coorExit   = new Coordonnée();

            for (int x = 0; x < maze.getSize().getX(); x++)
            {
                for (int y = 0; y < maze.getSize().getY(); y++)
                {
                    if (maze.getVal(x, y) == 1)
                    {
                        PlaceWall(maze, x, y);
                    }
                    else if (maze.getVal(x, y) == 2)
                    {
                        coorDepart.setVal(x + 1, y + 1);
                        PlaceEntryExit(maze, x, y, depart);
                    }
                    else if (maze.getVal(x, y) == 3)
                    {
                        instance = Instantiate(lockExit, new Vector3(x + 1, y + 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);

                        PlaceEntryExit(maze, x, y, exit);
                    }
                    else
                    {
                        instance = Instantiate(floor, new Vector3(x + 1, y + 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);
                    }
                }
            }

            for (int x = 0; x < maze.getSize().getX() + 2; x++) // add of invisible wall around the maze
            {
                for (int y = 0; y < maze.getSize().getY() + 2; y++)
                {
                    if (x == 0 || x == (maze.getSize().getX() + 1) || y == 0 || y == (maze.getSize().getY() + 1))
                    {
                        instance = Instantiate(invisibleWall, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);
                    }
                }
            }

            instance = Instantiate(player, new Vector3(coorDepart.getX(), coorDepart.getY(), 0f), Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);

            PlaceKeyAndGhost(boardHolder, maze, coorDepart, coorExit);
        }
Exemple #4
0
        private void BoardSetup(int sizeMap)
        {
            boardHolder = new GameObject("Board").transform;
            
            Map maze = Map.creerLabyrinthe(sizeMap, sizeMap);

            GameObject instance;

            Coordonnée coorDepart = new Coordonnée();
            Coordonnée coorExit = new Coordonnée();

            for (int x = 0; x < maze.getSize().getX(); x++)
            {
                for (int y = 0; y < maze.getSize().getY(); y++)
                {
                    if (maze.getVal(x, y) == 1)
                        PlaceWall(maze, x, y);
                    else if (maze.getVal(x, y) == 2)
                    {
                        coorDepart.setVal(x + 1, y + 1);
                        PlaceEntryExit(maze, x, y, depart);
                    }
                    else if (maze.getVal(x, y) == 3)
                    {
                        instance = Instantiate(lockExit, new Vector3(x + 1, y + 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);

                        PlaceEntryExit(maze, x, y, exit);
                    }
                    else
                    {
                        instance = Instantiate(floor, new Vector3(x + 1, y + 1, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);
                    }
                    
                }
            }

            for (int x = 0; x < maze.getSize().getX() + 2; x++) // add of invisible wall around the maze
            {
                for (int y = 0; y < maze.getSize().getY() + 2; y++)
                {
                    if (x == 0 || x == (maze.getSize().getX() + 1) || y == 0 || y == (maze.getSize().getY() + 1))
                    {
                        instance = Instantiate(invisibleWall, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                        instance.transform.SetParent(boardHolder);
                    }
                }
            }

            instance = Instantiate(player, new Vector3(coorDepart.getX(), coorDepart.getY(), 0f), Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);

            PlaceKeyAndGhost(boardHolder, maze, coorDepart, coorExit);
        }
Exemple #5
0
 public bool CheckDistance(Coordonnée a, Coordonnée b, int distance)
 {
     if ((Mathf.Abs(a.getX() - b.getX()) + Mathf.Abs(a.getY() - b.getY())) < distance)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #6
0
        public void PlaceKeyAndGhost(Transform boardHolder, Map carte, Coordonnée depart, Coordonnée exit)
        {
            List <Coordonnée> listCoorKey   = new List <Coordonnée>();
            List <Coordonnée> listCoorGhost = new List <Coordonnée>();

            int sizeMap       = Mathf.Min(carte.getSize().getX(), carte.getSize().getY());
            int distanceKey   = (sizeMap - (sizeMap % 1)) / 2;
            int distanceGhost = (sizeMap + 1) * 3 / 4;

            for (int x = 1; x < carte.getSize().getX() - 1; x++) // ajout de mur invisible autour du labyrinthe
            {
                for (int y = 1; y < carte.getSize().getY() - 1; y++)
                {
                    int contactWall = 0;
                    if (carte.getVal(x, y) == 0)
                    {
                        for (int i = x - 1; i < x + 2; i++)
                        {
                            for (int j = y - 1; j < y + 2; j++)
                            {
                                if (i == x || j == y)
                                {
                                    if (carte.getVal(i, j) == 1)
                                    {
                                        contactWall++;
                                    }
                                }
                            }
                        }
                        if (contactWall == 3 && CheckDistance(new Coordonnée(x, y), depart, distanceKey) && CheckDistance(new Coordonnée(x, y), exit, distanceKey))
                        {
                            listCoorKey.Add(new Coordonnée(x, y));
                        }
                        else if (CheckDistance(new Coordonnée(x, y), depart, distanceGhost))
                        {
                            listCoorGhost.Add(new Coordonnée(x, y));
                        }
                    }
                }
            }
            Coordonnée coorKey  = listCoorKey[Random.Range(0, listCoorKey.Count)];
            GameObject instance = Instantiate(key, new Vector3(coorKey.getX() + 1, coorKey.getY() + 1, 0f), Quaternion.identity) as GameObject;

            instance.transform.SetParent(boardHolder);

            Coordonnée coorGhost = listCoorGhost[Random.Range(0, listCoorGhost.Count)];

            instance = Instantiate(ghost, new Vector3(coorGhost.getX() + 1, coorGhost.getY() + 1, 0f), Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);
        }
Exemple #7
0
        public static void caseDA(Coordonnée taille, ref Coordonnée depart, ref Coordonnée arrivee)
        {
            int cote = Random.Range(1, 5);
            int a;
            int d;

            switch (cote)
            {
            case 1:
                d = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                a = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                depart.setX(d);
                depart.setY(taille.getY() - 1);

                arrivee.setX(a);
                arrivee.setY(0);
                break;

            case 2:
                d = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                a = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                depart.setX(taille.getX() - 1);
                depart.setY(d);

                arrivee.setX(0);
                arrivee.setY(a);
                break;

            case 3:
                d = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                a = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                depart.setX(d);
                depart.setY(0);

                arrivee.setX(a);
                arrivee.setY(taille.getY() - 1);
                break;

            case 4:
                d = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                a = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                depart.setX(0);
                depart.setY(d);

                arrivee.setX(taille.getX() - 1);
                arrivee.setY(a);
                break;
            }
        }
Exemple #8
0
        public static bool quickContact(Map carte, Coordonnée newBloc)
        {
            int x = newBloc.getX();
            int y = newBloc.getY();

            for (int i = x - 1; i < x + 2; i++)
            {
                for (int j = y - 1; j < y + 2; j++)
                {
                    if (i != x || j != y)
                    {
                        if (carte.getVal(i, j) == 1)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemple #9
0
        public static bool contact(Map carte, Coordonnée newBloc, List <Coordonnée> listeB, int bloc) //détermine si tout les cases vides (sans mur) sont en contact
        {
            List <Coordonnée> listeBloc = new List <Coordonnée>();

            for (int i = 0; i < listeB.Count; i++)
            {
                listeBloc.Add(new Coordonnée(listeB[i].getX(), listeB[i].getY()));
            }

            List <Coordonnée> listeContact = new List <Coordonnée>();

            Coordonnée baseCoor = new Coordonnée(1, 1);

            listeContact.Add(baseCoor);     //on peut commencer a chercher les contacts à partir de n'importe quel case
            listeBloc.Remove(baseCoor);     //on commence donc toujours par une case que l'on sait toujours vide

            int maxi = listeBloc.Count;

            listeBloc.Remove(newBloc);

            int a = 0;

            while ((a < listeContact.Count) && (maxi != listeContact.Count))
            {
                int b = 0;
                while (b < listeBloc.Count)
                {
                    if (((listeBloc[b].getX() == listeContact[a].getX()) && ((listeBloc[b].getY() == ((listeContact[a].getY()) - 1)) || (listeBloc[b].getY() == (listeContact[a].getY() + 1)))) || ((listeBloc[b].getY() == listeContact[a].getY()) && ((listeBloc[b].getX() == (listeContact[a].getX() - 1)) || (listeBloc[b].getX() == (listeContact[a].getX() + 1)))))
                    {
                        listeContact.Add(new Coordonnée(listeBloc[b].getX(), listeBloc[b].getY()));

                        listeBloc.RemoveAt(b);
                        b--;
                    }
                    b++;
                }
                a++;
            }
            return(maxi == listeContact.Count);
        }
Exemple #10
0
 public Coordonnée getSize()
 {
     Coordonnée result = new Coordonnée(sizeX, sizeY);
     return result;
 }
Exemple #11
0
 public void setVal(Coordonnée coor, int valeur)
 {
     map[coor.getY() * sizeX + coor.getX()] = valeur;
 }
Exemple #12
0
 public Map(Coordonnée taille)
 {
     map = new int[taille.x * taille.y];
     sizeX = taille.x;
     sizeY = taille.y;
 }
Exemple #13
0
 public int getVal(Coordonnée coor)
 {
     return(map[coor.getY() * sizeX + coor.getX()]);
 }
Exemple #14
0
        public static Map creerLabyrinthe(int largeur, int hauteur)
        {
            //on rend les dimensions impaire si elles ne le sont pas déjà
            int x = largeur - (largeur % 2) + 1;
            int y = hauteur - (hauteur % 2) + 1;
            Coordonnée taille = new Coordonnée(x, y);

            Map carte = new Map(taille);

            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 4);
                carte.setVal(i, y - 1, 4);
            }

            for (int j = 0; j < y; j++)
            {
                carte.setVal(0, j, 4);
                carte.setVal(x - 1, j, 4);
            }

            //on calcule le nombre de mur à créer avec une formule magique
            int arret = (x - 3) * (y - 3) / 2;

            //on crée la liste des blocs dans lesquels il est possible de faire un mur
            List<Coordonnée> listeLibre = new List<Coordonnée>();
            for (int i1 = 1; i1 < x - 1; i1++)
            {
                for (int j1 = 1; j1 < y - 1; j1++)
                {
                    if (i1 % 2 == 0 || j1 % 2 == 0)
                    {
                        listeLibre.Add(new Coordonnée(i1, j1));
                    }
                }
            }

            List<Coordonnée> listeBloc = new List<Coordonnée>();
            for (int i = 1; i < carte.getSize().getX() - 1; i++)
            {
                for (int j = 1; j < carte.getSize().getY() - 1; j++)
                {
                    if (carte.getVal(i, j) == 0)
                    {
                        listeBloc.Add(new Coordonnée(i, j));
                    }
                }
            }

            int mur = 0;

            int iteration = 0;
            
            while (mur < arret && listeLibre.Count != 0)   //boucle de création des murs
            {
                int nbRand = Random.Range(0, listeLibre.Count);
                Coordonnée bloc = listeLibre[nbRand];

                carte.setVal(bloc.getX(), bloc.getY(), 1);
                mur++;
                if(!quickContact(carte, bloc))
                {
                    if (!contact(carte, bloc, listeBloc, 0))
                    {
                        carte.setVal(bloc.getX(), bloc.getY(), 0);
                        mur--;
                    }
                    else listeBloc.Remove(bloc);
                }
                else listeBloc.Remove(bloc);
                
                listeLibre.RemoveAt(nbRand);
                iteration++;
            }

            //on change les murs extérieurs en murs normaux
            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 1);
                carte.setVal(i, y - 1, 1);
            }

            for (int j = 0; j < x; j++)
            {
                carte.setVal(0, j, 1);
                carte.setVal(x - 1, j, 1);
            }

            Coordonnée depart = new Coordonnée();
            Coordonnée arrivee = new Coordonnée();
            caseDA(taille, ref depart, ref arrivee);
            carte.setVal(depart.getX(), depart.getY(), 2);
            carte.setVal(arrivee.getX(), arrivee.getY(), 3);
            
            return carte;
        }
Exemple #15
0
        public static bool contact(Map carte, Coordonnée newBloc, List<Coordonnée> listeB, int bloc) //détermine si tout les cases vides (sans mur) sont en contact
        {
            List<Coordonnée> listeBloc = new List<Coordonnée>();
            for(int i = 0; i < listeB.Count; i++)
            {
                listeBloc.Add(new Coordonnée(listeB[i].getX(), listeB[i].getY()));
            }

            List<Coordonnée> listeContact = new List<Coordonnée>();

            Coordonnée baseCoor = new Coordonnée(1, 1);
            listeContact.Add(baseCoor);     //on peut commencer a chercher les contacts à partir de n'importe quel case
            listeBloc.Remove(baseCoor);     //on commence donc toujours par une case que l'on sait toujours vide

            int maxi = listeBloc.Count;

            listeBloc.Remove(newBloc);

            int a = 0;
            while ((a < listeContact.Count) && (maxi != listeContact.Count))
            {
                int b = 0;
                while (b < listeBloc.Count)
                {
                    if ( ((listeBloc[b].getX() == listeContact[a].getX()) && ((listeBloc[b].getY() == ((listeContact[a].getY()) - 1)) || (listeBloc[b].getY() == (listeContact[a].getY() + 1))) ) || ( (listeBloc[b].getY() == listeContact[a].getY()) && ((listeBloc[b].getX() == (listeContact[a].getX() - 1)) || (listeBloc[b].getX() == (listeContact[a].getX() + 1)))) )
                    {
                        listeContact.Add(new Coordonnée(listeBloc[b].getX(), listeBloc[b].getY() ) );
                        
                        listeBloc.RemoveAt(b);
                        b--;


                    }
                    b++;
                }
                a++;
            }
            return maxi == listeContact.Count;
        }
Exemple #16
0
 public static bool quickContact(Map carte, Coordonnée newBloc)
 {
     
     int x = newBloc.getX();
     int y = newBloc.getY();
     for (int i = x-1; i < x+2; i++)
     {
         for(int j = y-1; j < y+2; j++)
         {
             if(i != x || j != y)
             {
                 if (carte.getVal(i, j) == 1) return false;
             }
         }
     }
     return true;
 }
Exemple #17
0
        public static void caseDA(Coordonnée taille, ref Coordonnée depart, ref Coordonnée arrivee)
        {
            int cote = Random.Range(1, 5);            
            int a;
            int d;
            switch (cote)
            {
                case 1:
                    d = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                    a = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                    depart.setX(d);
                    depart.setY(taille.getY() - 1);

                    arrivee.setX(a);
                    arrivee.setY(0);
                    break;

                case 2:
                    d = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                    a = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                    depart.setX(taille.getX() - 1);
                    depart.setY(d);

                    arrivee.setX(0);
                    arrivee.setY(a);
                    break;

                case 3:
                    d = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                    a = (Random.Range(0, (taille.getX() - 1) / 2)) * 2 + 1;
                    depart.setX(d);
                    depart.setY(0);

                    arrivee.setX(a);
                    arrivee.setY(taille.getY() - 1);
                    break;

                case 4:
                    d = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                    a = (Random.Range(0, (taille.getY() - 1) / 2)) * 2 + 1;
                    depart.setX(0);
                    depart.setY(d);

                    arrivee.setX(taille.getX() - 1);
                    arrivee.setY(a);
                    break;
            }
        }
Exemple #18
0
 public void setVal(Coordonnée coor, int valeur)
 {
     map[coor.getY() * sizeX + coor.getX()] = valeur;
 }
Exemple #19
0
 public bool CheckDistance(Coordonnée a, Coordonnée b, int distance)
 {
     if ((Mathf.Abs(a.getX() - b.getX()) + Mathf.Abs(a.getY() - b.getY())) < distance) return false;
     else return true;
 }
Exemple #20
0
        public void PlaceKeyAndGhost(Transform boardHolder, Map carte, Coordonnée depart, Coordonnée exit)
        {
            List<Coordonnée> listCoorKey = new List<Coordonnée>();
            List<Coordonnée> listCoorGhost = new List<Coordonnée>();

            int sizeMap = Mathf.Min(carte.getSize().getX(), carte.getSize().getY());
            int distanceKey = (sizeMap - (sizeMap % 1)) / 2;
            int distanceGhost = (sizeMap + 1) * 3 / 4;
            
            for (int x = 1; x < carte.getSize().getX()-1; x++) // ajout de mur invisible autour du labyrinthe
            {
                for (int y = 1; y < carte.getSize().getY()-1; y++)
                {
                    int contactWall = 0;
                    if (carte.getVal(x, y) == 0)
                    {
                        
                        for (int i = x - 1; i < x + 2; i++)
                        {
                            for (int j = y - 1; j < y + 2; j++)
                            {
                                if (i == x || j == y)
                                {
                                    if (carte.getVal(i, j) == 1) contactWall++;
                                }
                            }
                        }
                        if (contactWall == 3 && CheckDistance(new Coordonnée(x, y), depart, distanceKey) && CheckDistance(new Coordonnée(x, y), exit, distanceKey)) listCoorKey.Add(new Coordonnée(x, y));
                        else if (CheckDistance(new Coordonnée(x, y), depart, distanceGhost)) listCoorGhost.Add(new Coordonnée(x, y));
                    }
                    
                }
            }
            Coordonnée coorKey = listCoorKey[Random.Range(0, listCoorKey.Count)];
            GameObject instance = Instantiate(key, new Vector3(coorKey.getX() + 1, coorKey.getY()+ 1, 0f), Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);

            Coordonnée coorGhost = listCoorGhost[Random.Range(0, listCoorGhost.Count)];
            instance = Instantiate(ghost, new Vector3(coorGhost.getX() + 1, coorGhost.getY() + 1, 0f), Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);
        }
Exemple #21
0
        public Coordonnée getSize()
        {
            Coordonnée result = new Coordonnée(sizeX, sizeY);

            return(result);
        }
Exemple #22
0
        public static Map creerLabyrinthe(int largeur, int hauteur)
        {
            //on rend les dimensions impaire si elles ne le sont pas déjà
            int        x      = largeur - (largeur % 2) + 1;
            int        y      = hauteur - (hauteur % 2) + 1;
            Coordonnée taille = new Coordonnée(x, y);

            Map carte = new Map(taille);

            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 4);
                carte.setVal(i, y - 1, 4);
            }

            for (int j = 0; j < y; j++)
            {
                carte.setVal(0, j, 4);
                carte.setVal(x - 1, j, 4);
            }

            //on calcule le nombre de mur à créer avec une formule magique
            int arret = (x - 3) * (y - 3) / 2;

            //on crée la liste des blocs dans lesquels il est possible de faire un mur
            List <Coordonnée> listeLibre = new List <Coordonnée>();

            for (int i1 = 1; i1 < x - 1; i1++)
            {
                for (int j1 = 1; j1 < y - 1; j1++)
                {
                    if (i1 % 2 == 0 || j1 % 2 == 0)
                    {
                        listeLibre.Add(new Coordonnée(i1, j1));
                    }
                }
            }

            List <Coordonnée> listeBloc = new List <Coordonnée>();

            for (int i = 1; i < carte.getSize().getX() - 1; i++)
            {
                for (int j = 1; j < carte.getSize().getY() - 1; j++)
                {
                    if (carte.getVal(i, j) == 0)
                    {
                        listeBloc.Add(new Coordonnée(i, j));
                    }
                }
            }

            int mur = 0;

            int iteration = 0;

            while (mur < arret && listeLibre.Count != 0)   //boucle de création des murs
            {
                int        nbRand = Random.Range(0, listeLibre.Count);
                Coordonnée bloc   = listeLibre[nbRand];

                carte.setVal(bloc.getX(), bloc.getY(), 1);
                mur++;
                if (!quickContact(carte, bloc))
                {
                    if (!contact(carte, bloc, listeBloc, 0))
                    {
                        carte.setVal(bloc.getX(), bloc.getY(), 0);
                        mur--;
                    }
                    else
                    {
                        listeBloc.Remove(bloc);
                    }
                }
                else
                {
                    listeBloc.Remove(bloc);
                }

                listeLibre.RemoveAt(nbRand);
                iteration++;
            }

            //on change les murs extérieurs en murs normaux
            for (int i = 0; i < x; i++)
            {
                carte.setVal(i, 0, 1);
                carte.setVal(i, y - 1, 1);
            }

            for (int j = 0; j < x; j++)
            {
                carte.setVal(0, j, 1);
                carte.setVal(x - 1, j, 1);
            }

            Coordonnée depart  = new Coordonnée();
            Coordonnée arrivee = new Coordonnée();

            caseDA(taille, ref depart, ref arrivee);
            carte.setVal(depart.getX(), depart.getY(), 2);
            carte.setVal(arrivee.getX(), arrivee.getY(), 3);

            return(carte);
        }
Exemple #23
0
 public int getVal(Coordonnée coor)
 {
     return map[coor.getY() * sizeX + coor.getX()];
 }
Exemple #24
0
 public Map(Coordonnée taille)
 {
     map   = new int[taille.x * taille.y];
     sizeX = taille.x;
     sizeY = taille.y;
 }