bool VerifierConnectionBatiment(Amenagement a)
        {
            int gauche = Math.Max(a.PosX - 1, 0);
            int droite = Math.Min(a.PosX + a.Taille, taille - 1);
            int haut   = Math.Max(a.PosY - 1, 0);
            int bas    = Math.Min(a.PosY + a.Taille, taille - 1);

            for (int i = gauche; i <= droite; i++)
            {
                for (int j = haut; j <= bas; j++)
                {
                    if (!(j == a.PosX - 1 && i == a.PosY + a.Taille) && !(j == a.PosX - 1 && i == a.PosY - 1) && !(j == a.PosX + a.Taille && i == a.PosY + a.Taille) && !(j == a.PosX + a.Taille && i == a.PosY - 1))
                    {
                        if (carte[i, j] != null && carte[i, j] is Route)
                        {
                            Amenagement t        = carte[i, j];
                            bool        connecte = PathFinding(new List <Route>(), new Queue <Route> (new[] { (t as Route) }));
                            if (connecte)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        public object Clone()
        {
            Amenagement amenagement = (Amenagement)MemberwiseClone();

            amenagement.idAmenagement = globalIdAmenagement;
            globalIdAmenagement      += 1;
            return(amenagement);
        }
        public void PlacerUnBatiment(Amenagement a, Ville v)
        {
            bool continuer = true;

            posX = 0;
            posY = 0;

            Console.Clear();
            AfficherTerrain();

            while (continuer)
            {
                Amenagement temp = (Amenagement)a.Clone();

                Console.SetCursorPosition(posX, posY);
                bool dispo = VerifierPlace(a);
                AfficherPlace(a, dispo);

                ConsoleKey key = Console.ReadKey(true).Key;
                DeplacementCurseur(key);

                if (key == ConsoleKey.Enter)
                {
                    if (dispo)
                    {
                        if (v.PeutAjouterAmenagement(temp))
                        {
                            PoserAmenagement(temp);
                            Console.Clear();
                            AfficherTerrain();

                            temp.PosX = posX;
                            temp.PosY = posY;

                            if (temp is Logement)
                            {
                                v.AjoutLogement((temp as Logement));
                            }
                            if (temp is Route)
                            {
                                VerifierConnectionToutLesBatiments(v.Amenagements);
                            }
                            else
                            {
                                VerifierConnectionBatiment(temp);
                            }
                        }
                    }
                }
                if (key == ConsoleKey.Escape)
                {
                    continuer = false;
                }

                Console.Clear();
                AfficherTerrain();
            }
        }
 void PoserAmenagement(Amenagement a)
 {
     for (int i = posY; i < posY + a.Taille; i++)
     {
         for (int j = posX; j < posX + a.Taille; j++)
         {
             carte[i, j] = a;
         }
     }
 }
        public void ObserverLaCarte(Ville v)
        {
            bool continuer = true;

            posX = 0;
            posY = 0;
            Console.Clear();
            AfficherTerrain();
            AfficherInfoAmenagement();

            while (continuer)
            {
                Console.SetCursorPosition(posX, posY);
                ConsoleKey key = Console.ReadKey(true).Key;

                DeplacementCurseur(key);

                Console.Clear();
                AfficherTerrain();
                AfficherInfoAmenagement();

                if (key == ConsoleKey.Delete)
                {
                    Amenagement a = SupprimerBatiment();
                    if (a != null)
                    {
                        v.SupprimerAmenagement(a);
                    }
                    Console.Clear();
                    AfficherTerrain();
                    VerifierConnectionToutLesBatiments(v.Amenagements);
                }
                if (key == ConsoleKey.Enter)
                {
                    Amenagement a = carte[posY, posX];
                    if (a != null)
                    {
                        if (a is IParametrable)
                        {
                            (a as IParametrable).ModifierParametre();
                        }
                    }
                }
                if (key == ConsoleKey.Escape)
                {
                    continuer = false;
                }
            }
        }
Exemplo n.º 6
0
        public void PlacerUnBatiment(Amenagement a, Ville v)
        {
            PoserAmenagement(a);

            if (a is Logement)
            {
                v.AjoutLogement((a as Logement));
            }
            if (a is Route)
            {
                VerifierConnectionToutLesBatiments(v.Amenagements);
            }
            else
            {
                VerifierConnectionBatiment(a);
            }
        }
 bool VerifierPlace(Amenagement a)
 {
     if (posY + a.Taille > taille || posX + a.Taille > taille)
     {
         return(false);
     }
     for (int i = posY; i < posY + a.Taille; i++)
     {
         for (int j = posX; j < posX + a.Taille; j++)
         {
             if (carte[i, j] != null)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemplo n.º 8
0
        public void SupprimerBatiment(Amenagement a)
        {
            if (a != null)
            {
                int id = a.IdAmenagement;

                for (int i = Math.Max(0, a.PosY - a.Taille); i < Math.Min(taille, a.PosY + a.Taille); i++)
                {
                    for (int j = Math.Max(0, a.PosX - a.Taille); j < Math.Min(taille, a.PosX + a.Taille); j++)
                    {
                        if (carte[i, j] != null && carte[i, j].IdAmenagement == id)
                        {
                            carte[i, j] = null;
                        }
                    }
                }
            }
        }
Exemplo n.º 9
0
        public bool VerifierPlace(Amenagement a)
        {
            if (a.PosY + a.Taille > taille || a.PosX + a.Taille > taille || a.PosX < 0 || a.PosY < 0)
            {
                return(false);
            }


            for (int i = a.PosY; i < a.PosY + a.Taille; i++)
            {
                for (int j = a.PosX; j < a.PosX + a.Taille; j++)
                {
                    if (carte[i, j] != null)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 10
0
        Amenagement SupprimerBatiment()
        {
            Amenagement a = carte[posY, posX];

            if (a != null)
            {
                int id = a.IdAmenagement;

                for (int i = Math.Max(0, posY - a.Taille); i < Math.Min(taille, posY + a.Taille); i++)
                {
                    for (int j = Math.Max(0, posX - a.Taille); j < Math.Min(taille, posX + a.Taille); j++)
                    {
                        if (carte[i, j] != null && carte[i, j].IdAmenagement == id)
                        {
                            carte[i, j] = null;
                        }
                    }
                }
            }
            return(a);
        }
Exemplo n.º 11
0
        void AfficherPlace(Amenagement a, bool disponible)
        {
            Console.BackgroundColor = (disponible) ? ConsoleColor.Green : ConsoleColor.Red;

            for (int i = posY; i < Math.Min(posY + a.Taille, taille); i++)
            {
                for (int j = posX; j < Math.Min(posX + a.Taille, taille); j++)
                {
                    Console.SetCursorPosition(j, i);
                    if (carte[i, j] != null)
                    {
                        Console.ForegroundColor = carte[i, j].Couleur;
                        Console.Write("V");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                    else
                    {
                        Console.Write("O");
                    }
                }
            }
            Console.SetCursorPosition(posX, posY);
            Console.BackgroundColor = ConsoleColor.Black;
        }
Exemplo n.º 12
0
        void VerifierConnectionBatiment(Amenagement a)
        {
            /*
             * int gauche = Math.Max(a.PosX - 1, 0);
             * int droite = Math.Min(a.PosX + a.Taille, taille - 1);
             * int haut = Math.Max(a.PosY - 1, 0);
             * int bas = Math.Min(a.PosY + a.Taille, taille - 1);
             * for (int i = gauche; i <= droite; i++)
             * {
             *  for(int j = haut; j <= bas; j++)
             *  {
             *      if(!(j == a.PosX - 1 && i == a.PosY + a.Taille) && !(j == a.PosX - 1 && i == a.PosY - 1) && !(j == a.PosX + a.Taille && i == a.PosY + a.Taille) && !(j == a.PosX + a.Taille && i == a.PosY - 1))
             *      {
             *          if(carte[i, j] != null && carte[i, j] is Route)
             *          {
             *              Amenagement t = carte[i, j];
             *              bool connecte = PathFinding(new List<Route>(), new Queue<Route> ( new[]{(t as Route) }));
             *              if (connecte)
             *              {
             *                  (a as Batiment).EstConnecte = true;
             *                  return;
             *              }
             *
             *          }
             *      }
             *  }
             * }
             *
             * (a as Batiment).EstConnecte = false;
             *
             */

            if (a.PosX > 0)
            {
                for (int i = a.PosY; i < a.PosY + a.Taille; i++)
                {
                    if (carte[i, a.PosX - 1] != null && carte[i, a.PosX - 1] is Route)
                    {
                        Amenagement t        = carte[i, a.PosX - 1];
                        bool        connecte = PathFinding(new List <Route>(), new Queue <Route>(new[] { (t as Route) }));
                        if (connecte)
                        {
                            (a as Batiment).EstConnecte = true;
                            return;
                        }
                    }
                }
            }
            if (a.PosX + a.Taille < taille - 1)
            {
                for (int i = a.PosY; i < a.PosY + a.Taille; i++)
                {
                    if (carte[i, a.PosX + a.Taille] != null && carte[i, a.PosX + a.Taille] is Route)
                    {
                        Amenagement t        = carte[i, a.PosX + a.Taille];
                        bool        connecte = PathFinding(new List <Route>(), new Queue <Route>(new[] { (t as Route) }));
                        if (connecte)
                        {
                            (a as Batiment).EstConnecte = true;
                            return;
                        }
                    }
                }
            }
            if (a.PosY > 0)
            {
                for (int i = a.PosX; i < a.PosX + a.Taille; i++)
                {
                    if (carte[a.PosY - 1, i] != null && carte[a.PosY - 1, i] is Route)
                    {
                        Amenagement t        = carte[a.PosY - 1, i];
                        bool        connecte = PathFinding(new List <Route>(), new Queue <Route>(new[] { (t as Route) }));
                        if (connecte)
                        {
                            (a as Batiment).EstConnecte = true;
                            return;
                        }
                    }
                }
            }
            if (a.PosY + a.Taille < taille - 1)
            {
                for (int i = a.PosX; i < a.PosX + a.Taille; i++)
                {
                    if (carte[a.PosY + a.Taille, i] != null && carte[a.PosY + a.Taille, i] is Route)
                    {
                        Amenagement t        = carte[a.PosY + a.Taille, i];
                        bool        connecte = PathFinding(new List <Route>(), new Queue <Route>(new[] { (t as Route) }));
                        if (connecte)
                        {
                            (a as Batiment).EstConnecte = true;
                            return;
                        }
                    }
                }
            }

            if (a is Batiment)
            {
                (a as Batiment).EstConnecte = false;
            }
        }