Beispiel #1
0
 public ataque(unit atacante_, unit defensor_, DateTime restante_, int cont_)
 {
     atacante = atacante_;
     defensor = defensor_;
     x        = atacante_.x;
     y        = atacante_.y;
     emisor   = atacante_.user;
     receptor = defensor_.user;
     fecha    = DateTime.Now; //obtener tiempo actual para la fecha
     restante = restante_;    //tiempo restante de la partida
     cont     = cont_;        //no de ataque
 }
Beispiel #2
0
        public void insertar(String col_, int fila, String id, String user_, int existe_)
        {
            char[] array = col_.ToCharArray();
            int    col   = char.ToUpper(array[0]) - 64;//convertir a valor numérico
            unit   nuevo = new unit(id, col, fila);

            nuevo.user   = user_;
            nuevo.existe = existe_;
            nivel insert = buscarnivel(nuevo.nivel);

            if (insert != null)
            {
                insert.insertar(nuevo, col, fila);
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public unit buscar(int val, String coord)
        {
            unit temp = primero;

            if (temp != null)
            {
                if (coord.Equals("X"))//buscar en las coordenadas en x
                {
                    while (temp != null)
                    {
                        if (temp.x == val)
                        {
                            return(temp);
                        }
                        else
                        {
                            temp = temp.der;
                        }
                    }
                }
                else if (coord.Equals("Y"))//buscar en las coordenadas en y
                {
                    while (temp != null)
                    {
                        if (temp.y == val)
                        {
                            return(temp);
                        }
                        else
                        {
                            temp = temp.abajo;
                        }
                    }
                }
            }
            return(null);
        }
Beispiel #5
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);
        }
Beispiel #6
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;
                            }
                        }
                    }
                }
            }
        }