Exemplo n.º 1
0
        private void LeerArchivo(string path)
        {
            XmlDocument a = new XmlDocument();

            a.Load(path);
            XmlNode raiz = a.DocumentElement;
            XmlAttributeCollection atributos = raiz.Attributes;
            XmlNode name     = atributos.Item(0);
            XmlNode width    = atributos.Item(1);
            XmlNode height   = atributos.Item(2);
            XmlNode accident = atributos.Item(3);
            XmlNode sicknnes = atributos.Item(4);
            XmlNode crime    = atributos.Item(5);
            XmlNode fire     = atributos.Item(6);

            nombre          = name.Value;
            ancho           = Convert.ToInt32(width.Value);
            alto            = Convert.ToInt32(height.Value);
            PROBAaccidente  = Convert.ToDouble(accident.Value.Replace(".", ","));
            PROBAenfermedad = Convert.ToDouble(sicknnes.Value.Replace(".", ","));
            PROBAasalto     = Convert.ToDouble(crime.Value.Replace(".", ","));
            PROBAincendio   = Convert.ToDouble(fire.Value.Replace(".", ","));
            building        = a.GetElementsByTagName("building");
            material        = a.GetElementsByTagName("material");
            streetlight     = a.GetElementsByTagName("streetlight");
            Materiales      = new List <Material>();
            Semaforos       = new List <SemaforoBackEnd>();
            Edificios       = new List <Edificio>();
            mapaDeCeldas    = new Celdas[ancho, alto];

            matriz = new int[ancho, alto];
            for (int i = 0; i < ancho; i++)
            {
                for (int j = 0; j < alto; j++)
                {
                    matriz[i, j] = -5;
                }
            }
            for (int j = 0; j < material.Count; j++)
            {
                Material mater;
                atA = material.Item(j).Attributes;
                XmlNode W = atA.Item(1);
                XmlNode K = atA.Item(2);
                w     = Convert.ToDouble(W.Value.Replace(".", ",")); //sick
                k     = Convert.ToDouble(K.Value.Replace(".", ",")); //inflamability
                mat   = atA.Item(0).Value;
                mater = new Material(mat, w, k);
                Materiales.Add(mater);
            }

            for (int j = 0; j < streetlight.Count; j++)
            {
                SemaforoBackEnd semaforo;
                Celdas[]        celdas = new Celdas[streetlight.Item(j).ChildNodes.Count];
                at   = streetlight.Item(j).ChildNodes;
                time = Convert.ToInt32(streetlight.Item(j).Attributes.Item(0).Value);
                for (int i = 0; i < streetlight.Item(j).ChildNodes.Count; i++)
                {
                    atA       = at.Item(i).Attributes;
                    w         = Convert.ToInt32(atA.Item(0).Value);
                    k         = Convert.ToInt32(atA.Item(1).Value);
                    mat       = "semaforo";
                    celdas[i] = new Celdas((int)w, (int)k, establecerMaterial(mat), "semaforo");
                    matriz[(int)w, (int)k] = -2;
                }
                semaforo         = new SemaforoBackEnd(celdas, time);
                restarSemaforos += semaforo.restar;
                Semaforos.Add(semaforo);
            }

            for (int j = 0; j < building.Count; j++)
            {
                Edificio edificio;
                at             = building.Item(j).ChildNodes;
                nombreEdificio = building.Item(j).Attributes.Item(0).Value;
                Celdas[] celdas = new Celdas[building.Item(j).ChildNodes.Count];
                for (int i = 0; i < building.Item(j).ChildNodes.Count; i++)
                {
                    atA       = at.Item(i).Attributes;
                    w         = Convert.ToInt32(atA.Item(0).Value);
                    k         = Convert.ToInt32(atA.Item(1).Value);
                    mat       = atA.Item(2).Value;
                    celdas[i] = new Celdas((int)w, (int)k, establecerMaterial(mat), nombreEdificio);
                    matriz[(int)w, (int)k]       = 0;
                    mapaDeCeldas[(int)w, (int)k] = celdas[i];
                }
                edificio = new Edificio(celdas, building.Item(j).ChildNodes.Item(0).Value);
                Edificios.Add(edificio);
            }

            MCalles = new MatrizCalles(matriz);
        }
Exemplo n.º 2
0
 public VehiculoBackEnd(int x, int y)
 {
     posX   = x;
     posY   = y;
     calles = Program.MCalles;
 }