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); }
public nivel(int val_, int sizex_, int sizey_) { horizontal = null; vertical = null; val = val_; sizex = sizex_; sizey = sizey_; sup = null; inf = null; }
public void graficar(mo ingreso) { //generar grafo del primer nivel nivel temp = ingreso.primero; while (temp != null) { graficarnivel(temp); temp = temp.sup; } }
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); } }
public nivel buscarnivel(int lvl) { nivel temp = primero; while (temp != null) { if (temp.val == lvl) { return(temp); } else { temp = temp.sup; } } return(null); }
public void insertnivel() { if (primero == null) { primero = new nivel(1, this.sizex, this.sizey); } int lvl = 2; nivel temp = primero; while (lvl < 5) { temp.sup = new nivel(lvl, this.sizex, this.sizey); temp.sup.inf = temp; lvl++; temp = temp.sup; } }
public unit buscar(int x_, int y_, int z_) { //obtener el nivel de búsqueda nivel temp = primero; while (temp != null) { if (temp.val == z_) { break; } else { temp = temp.sup; } } return(temp.buscar(x_, y_)); }
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); }