Пример #1
0
 public pos(int val_)
 {
     primero   = null;
     val       = val_;
     siguiente = null;
     anterior  = null;
 }
Пример #2
0
        public mo finaldestruidos(mo ingreso)
        {
            //crear tablero de retorno con las mismas caracteristicas
            mo    ret     = new mo(ingreso.sizex, ingreso.sizey, ingreso.variante, ingreso.tiempo);
            nivel templvl = ingreso.primero;

            //recorrer niveles
            while (templvl != null)
            {
                if (templvl.horizontal != null)
                {
                    pos tempx = templvl.horizontal.primero;
                    //recorrer columnas
                    while (tempx != null)
                    {
                        unit temp = tempx.primero;
                        while (temp != null)
                        {//insertar si aun existe en el tablero
                            if (temp.existe == 0)
                            {
                                String columna = ((char)(temp.x + 64)).ToString();//convertir coordenada a char y luego a string
                                ret.insertar(columna, temp.y, temp.id, temp.user, temp.existe);
                            }
                            temp = temp.abajo;
                        }
                        tempx = tempx.siguiente;
                    }
                }

                templvl = templvl.sup;
            }
            return(ret);
        }
Пример #3
0
        public pos insertar(int val_)
        {
            pos nuevo = new pos(val_);
            pos temp  = primero;

            if (temp == null)
            {
                primero = nuevo;
                return(nuevo);
            }

            else
            {
                //insertar al inicio
                if (temp.val > nuevo.val)
                {
                    temp.anterior   = nuevo;
                    nuevo.siguiente = temp;
                    primero         = nuevo;
                    return(nuevo);
                }
                else
                {
                    //insertar al medio
                    while (temp.siguiente != null)
                    {
                        if (temp.siguiente.val > nuevo.val)
                        {
                            nuevo.siguiente         = temp.siguiente;
                            temp.siguiente.anterior = nuevo;
                            nuevo.anterior          = temp;
                            temp.siguiente          = nuevo;
                            return(nuevo);
                        }
                        else
                        {
                            temp = temp.siguiente;
                        }
                    }
                    temp.siguiente = nuevo;
                    nuevo.anterior = temp;
                    return(nuevo);
                }
            }
            return(null);
        }
Пример #4
0
        //buscar un nodop
        public unit buscar(int x_, int y_)
        {
            //buscar la columna
            pos  tempx = horizontal.buscar(x_);
            unit temp  = tempx.primero;

            while (temp != null)
            {
                if (temp.y == y_)
                {
                    return(temp);
                }
                else
                {
                    temp = temp.abajo;
                }
            }
            return(null);
        }
Пример #5
0
        public pos buscar(int val_)
        {
            pos temp = primero;

            if (temp != null)
            {
                while (temp != null)
                {
                    if (temp.val == val_)
                    {
                        return(temp);
                    }
                    else
                    {
                        temp = temp.siguiente;
                    }
                }
            }
            return(null);
        }
Пример #6
0
        //eliminar una coordenada
        public void eliminar(int val_)
        {
            pos temp = buscar(val_);

            if (temp != null)
            {
                if (temp.anterior != null)
                {
                    temp.anterior.siguiente = temp.siguiente;
                }
                else
                {
                    primero = temp.siguiente;
                    temp.siguiente.anterior = null;
                }
                if (temp.siguiente != null)
                {
                    temp.siguiente.anterior = temp.anterior;
                }
            }
        }
Пример #7
0
        public void graficarnivel(nivel ingreso)
        {
            String dotgraph = "Digraph nivel" + ingreso.val.ToString() + "{\nRankdir=TD\nnode [shape =rectangle]";

            if (ingreso.horizontal != null)
            {
                pos tempx = ingreso.horizontal.primero;
                //agregar nodos de las cabeceras
                dotgraph += "{rank=min;";
                while (tempx.siguiente != null)
                {
                    dotgraph += "Pos" + tempx.val.ToString() + "x [label=\"" + "Pos" + tempx.val.ToString() + "x\"];\n";
                    tempx     = tempx.siguiente;
                }
                dotgraph += "Pos" + tempx.val.ToString() + "x [label=\"" + "Pos" + tempx.val.ToString() + "x\"]};\n";

                //agregar apuntadores de coordenadas en x
                tempx = ingreso.horizontal.primero;
                while (tempx.siguiente != null)
                {
                    dotgraph += "Pos" + tempx.val.ToString() + "x -> " + "Pos" + tempx.siguiente.val.ToString() + "x;\n";
                    dotgraph += "Pos" + tempx.siguiente.val.ToString() + "x -> " + "Pos" + tempx.val.ToString() + "x;\n";
                    tempx     = tempx.siguiente;
                }
                //agregar filas
                pos tempy = ingreso.vertical.primero;
                while (tempy != null)
                {
                    dotgraph += "{rank=same;" + "Pos" + tempy.val.ToString() + "y [label=\"" + "Pos" + tempy.val.ToString() + "y\"]";
                    unit temp = tempy.primero;
                    while (temp != null)
                    {
                        dotgraph += ";Unit" + temp.id + temp.x.ToString() + temp.y.ToString();
                        dotgraph += " [label=\"Unidad: " + temp.id + "\nHp: " + temp.hp.ToString() + "\nAtaque: " + temp.atk.ToString() + "\nMovimiento: " + temp.mov.ToString() + "\"]";
                        temp      = temp.der;
                    }
                    dotgraph += "};\n";
                    tempy     = tempy.siguiente;
                }
                //agregar apuntadores verticales
                tempx = ingreso.horizontal.primero;
                while (tempx != null)
                {
                    unit temp = tempx.primero;
                    dotgraph += "Pos" + tempx.val.ToString() + "x -> Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + ";\n";
                    while (temp.abajo != null)
                    {
                        dotgraph += "Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + " -> " + "Unit" + temp.abajo.id + temp.abajo.x.ToString() + temp.abajo.y.ToString() + ";\n";
                        dotgraph += "Unit" + temp.abajo.id + temp.abajo.x.ToString() + temp.abajo.y.ToString() + " -> " + "Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + ";\n";
                        temp      = temp.abajo;
                    }
                    tempx = tempx.siguiente;
                }
                //agregar apuntadores de cabeceras en y
                tempy = ingreso.vertical.primero;
                while (tempy.siguiente != null)
                {
                    dotgraph += "Pos" + tempy.val.ToString() + "y -> " + "Pos" + tempy.siguiente.val.ToString() + "y;\n";
                    dotgraph += "Pos" + tempy.siguiente.val.ToString() + "y -> " + "Pos" + tempy.val.ToString() + "y;\n";
                    tempy     = tempy.siguiente;
                }
                //agregar apuntadores horizontales
                tempy = ingreso.vertical.primero;
                while (tempy != null)
                {
                    unit temp = tempy.primero;
                    dotgraph += "Pos" + tempy.val.ToString() + "y -> Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + ";\n";
                    while (temp.der != null)
                    {
                        dotgraph += "Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + " -> " + "Unit" + temp.der.id + temp.der.x.ToString() + temp.der.y.ToString() + ";\n";
                        dotgraph += "Unit" + temp.der.id + temp.der.x.ToString() + temp.der.y.ToString() + " -> " + "Unit" + temp.id + temp.x.ToString() + temp.y.ToString() + ";\n";
                        temp      = temp.der;
                    }
                    tempy = tempy.siguiente;
                }
            }

            //terminar grafo
            dotgraph += "}\n";
            //generar grafo
            guardar(dotgraph, ingreso.val);
        }
Пример #8
0
 public coord()
 {
     primero = null;
 }
Пример #9
0
        //insertar una unidad en el nivel
        public void insertar(unit nuevo, int x, int y)
        {
            //no realizar acciones si las coordenadas están afuera del tamaño del tablero
            if (x > this.sizex)
            {
                return;
            }
            if (y > this.sizey)
            {
                return;
            }
            if (horizontal == null)
            {
                horizontal = new coord();
            }
            if (vertical == null)
            {
                vertical = new coord();
            }
            //insertar en las coordenadas en x
            pos tempx = horizontal.buscar(x);

            if (tempx == null)
            {
                tempx = horizontal.insertar(x);              //insertar nueva coordenada en x
            }
            unit ret = tempx.buscar(x, "X");

            if (ret == null)
            {
                //obtener el primer valor en la columna de tempx
                ret = tempx.primero;
                if (ret == null)
                {
                    tempx.primero = nuevo;
                }
                else
                {
                    //insertar al inicio en la columna de tempx
                    if (ret.y > nuevo.y)
                    {
                        ret.arriba    = nuevo;
                        nuevo.abajo   = ret;
                        tempx.primero = nuevo;
                    }
                    else
                    {//insertar al medio
                        while (ret.abajo != null)
                        {
                            if (ret.abajo.y > nuevo.y)
                            {
                                nuevo.abajo      = ret.abajo;
                                nuevo.arriba     = ret;
                                ret.abajo.arriba = nuevo;
                                ret.abajo        = nuevo;
                                break;
                            }
                            else
                            {
                                ret = ret.abajo;
                            }
                            //insertar al final
                            if (ret.abajo == null)
                            {
                                ret.abajo    = nuevo;
                                nuevo.arriba = ret;
                            }
                        }
                    }
                }
            }

            //insertar en las coordenadas en y
            pos tempy = vertical.buscar(y);

            if (tempy == null)
            {
                tempy = vertical.insertar(y);               //insertar nueva coordenada en x
            }
            unit rety = tempy.buscar(y, "Y");

            if (rety == null)
            {
                //obtener el primer valor en la columna de tempx
                rety = tempy.primero;
                if (rety == null)
                {
                    tempy.primero = nuevo;
                }
                else
                {
                    //insertar al inicio en la columna de tempx
                    if (rety.x > nuevo.x)
                    {
                        rety.izq      = nuevo;
                        nuevo.der     = rety;
                        tempy.primero = nuevo;
                    }
                    else
                    {//insertar al medio
                        while (rety.der != null)
                        {
                            if (rety.der.x > nuevo.x)
                            {
                                nuevo.der    = rety.der;
                                nuevo.izq    = rety;
                                rety.der.izq = nuevo;
                                rety.der     = nuevo;
                                break;
                            }
                            else
                            {
                                rety = rety.der;
                            }
                            //insertar al final
                            if (rety.der == null)
                            {
                                rety.der  = nuevo;
                                nuevo.izq = rety;
                            }
                        }
                    }
                }
            }
        }