public void TurnoJugador(Button button) { int columnas = (int)Session["columnas"] + 1; int filas = (int)Session["filas"] + 1; List <Ficha> fichas = (List <Ficha>)Session["fichas"]; Boolean turno = (Boolean)Session["turno"]; Juego metodos = new Juego(); Boolean apertura = AperturaPersonalizada(false); if (fichas.Count >= 4) { if (metodos.ValidadAccion(button)) { Accion(button); metodos.Limpiar((int)Session["columnas"] + 1, (int)Session["filas"] + 1); metodos.MovimientosPosibles((Boolean)Session["turno"], (int)Session["columnas"] + 1, (int)Session["filas"] + 1); ValidarGanadores(); } } else if (apertura) { if (metodos.ValidadAccion(button)) { Accion(button); if (fichas.Count == 4) { metodos.MovimientosPosibles((Boolean)Session["turno"], (int)Session["columnas"] + 1, (int)Session["filas"] + 1); } int[,] matriz = (int[, ])Session["matriz"]; int[] fichasT = metodos.ContarFichas(matriz, columnas, filas); ImprimirMatriz(matriz, columnas, filas); int fichasJ1 = fichasT[0]; int fichasJ2 = fichasT[1]; Label10.Text = "" + (int)Session["movimientosJ1"]; Label18.Text = "" + (int)Session["movimientosJ2"]; Label8.Text = "" + fichasJ1; Label16.Text = "" + fichasJ2; } } }
public void LimpiarTablero(List <Ficha> fichas, Tablero tab, LinkedList <string> listaJ1, LinkedList <string> listaJ2) { Juego metodos = new Juego(); int[,] matriz = new int[tab.columnas, tab.filas]; foreach (Ficha item in fichas) { int[] coor = metodos.Coordenada(item.columna + item.fila); if (item.color == listaJ1.Find(item.color).Value) { matriz[coor[0], coor[1]] = 2; } else if (item.color == listaJ2.Find(item.color).Value) { matriz[coor[0], coor[1]] = 1; } } Session["matriz"] = matriz; ImprimirMatriz(matriz, tab.columnas, tab.filas); metodos.Limpiar(tab.columnas, tab.filas); }
protected void Page_Load(object sender, EventArgs e) { AgregarCheck(); if (!(Boolean)Session["partida"]) { Session["movimientosJ1"] = 0; Session["movimientosJ2"] = 0; Session["partida"] = true; Session["matriz"] = matrizM; Session["fichas"] = fichasM; Session["ultima"] = ultimaM; Session["turno"] = false; Session["tablero"] = null; } else { if (Session["tablero"] != null) { Tablero tablero = new Tablero(); tablero.columnas = int.Parse(DropDownList2.SelectedValue); tablero.filas = int.Parse(DropDownList1.SelectedValue); Tablero(tablero.columnas, tablero.filas); ImprimirBotones(); List <Ficha> fichas = (List <Ficha>)Session["fichas"]; Juego metodos = new Juego(); } } Label4.Text = (string)Session["usuario"]; if (!(Boolean)Session["jugador2"]) { Label12.Text = "Maquina"; } else { Label12.Text = (string)Session["j2"]; } MostrarTurno(); }
public void CargarPartida() { LinkedList <String> Listaj1 = (LinkedList <String>)Session["coloresJ1"]; LinkedList <String> Listaj2 = (LinkedList <String>)Session["coloresJ2"]; Juego metodos = new Juego(); Ficha ultima = new Ficha(); List <Ficha> fichas = new List <Ficha>(); XmlDocument archivo = new XmlDocument(); archivo.Load(Server.MapPath("~/Xml/partidaExt.xml")); int numero = 0; Boolean turno; int jugador = 0; Tablero tab = new Tablero(); foreach (XmlElement item in archivo.DocumentElement) { Ficha fi = new Ficha(); for (int i = 0; i < item.ChildNodes.Count; i++) { string valor = item.ChildNodes[i].InnerText.Trim(); String nombre = item.ChildNodes[i].LocalName; switch (item.ChildNodes[i].LocalName.ToLower()) { case "columnas": tab.columnas = int.Parse(valor); break; case "filas": tab.filas = int.Parse(valor); break; case "jugador1": jugador = 1; break; case "jugador2": jugador = 2; break; case "tablero": jugador = 0; break; case "color": if (jugador == 1) { Listaj1.AddLast(valor); } else if (jugador == 2) { Listaj2.AddLast(valor); } else { fi.color = valor; } break; case "columna": fi.columna = valor; break; case "fila": fi.fila = valor; break; case "siguienteTiro": fi.color = valor; break; case "modalidad": if (valor == "inverso") { Session["inverso"] = true; CheckBox21.Checked = true; } else { Session["inverso"] = false; CheckBox21.Checked = false; } break; default: numero++; Console.WriteLine(numero); break; } } if (fi.columna == null) { ultima = fi; } else { fichas.Add(fi); } } Session["fichas"] = fichas; Session["ultima"] = ultima; Session["coloresJ1"] = Listaj1; Session["coloresJ2"] = Listaj2; Session["columnas"] = tab.columnas - 1; Session["filas"] = tab.filas - 1; Session["inverso"] = true; Tablero(tab.columnas, tab.filas); LimpiarTablero(fichas, tab, Listaj1, Listaj2); ImprimirFichas(); if (ultima.color == "negro") { turno = false; Session["turno"] = turno; } else { turno = true; Session["turno"] = turno; } metodos.MovimientosPosibles(turno, tab.columnas, tab.filas); ValidarGanadores(); MostrarTurno(); }
public void Accion(Button button) { LinkedList <String> Listaj1 = (LinkedList <String>)Session["coloresJ1"]; LinkedList <String> Listaj2 = (LinkedList <String>)Session["coloresJ2"]; Color color = new Color(); string nomColor; Juego metodos = new Juego(); Ficha ultima = (Ficha)Session["ultima"]; Ficha ultimaJ1 = (Ficha)Session["ultimaJ1"]; Ficha ultimaJ2 = (Ficha)Session["ultimaFichaJ2"]; Boolean turno = (Boolean)Session["turno"]; List <Ficha> fichas = (List <Ficha>)Session["fichas"]; int[,] matriz = (int[, ])Session["matriz"]; Ficha ficha = new Ficha(); int[] posicionM = metodos.Coordenada(button.ID); if (turno) { color = ColoresTurno(turno, Listaj2, ultimaJ2); nomColor = NomColor(color); ficha.color = nomColor; matriz[posicionM[0], posicionM[1]] = 1; } else { color = ColoresTurno(turno, Listaj1, ultimaJ1); nomColor = NomColor(color); ficha.color = nomColor; matriz[posicionM[0], posicionM[1]] = 2; } char[] posicion = button.ID.ToCharArray(); ficha.columna = posicion[0].ToString(); string numero; try { numero = posicion[1].ToString() + posicion[2].ToString(); } catch (Exception) { numero = posicion[1].ToString(); } ficha.fila = numero; fichas.Add(ficha); metodos.Movimiento(ficha, turno, (int[, ])Session["matriz"], (int)Session["columnas"] + 1, (int)Session["filas"] + 1, ficha.color); ImprimirFicha(ficha, color); if (!turno) { ultima.color = nomColor; } else { ultima.color = nomColor; } Session["fichas"] = fichas; Session["ultima"] = ultima; Session["turno"] = !turno; SumTurno(); }
public void ValidarGanadores() { int columnas = (int)Session["columnas"] + 1; int filas = (int)Session["filas"] + 1; Juego metodos = new Juego(); Partida partida = new Partida(); int[,] matriz = (int[, ])Session["matriz"]; int[] fichas = metodos.ContarFichas(matriz, columnas, filas); ImprimirMatriz(matriz, columnas, filas); int fichasJ1 = fichas[0]; int fichasJ2 = fichas[1]; int fjugador1, fjugador2; Boolean condicion1 = fichasJ1 > fichasJ2; Boolean condicion2 = fichasJ1 < fichasJ2; Boolean modoInverso = (Boolean)Session["inverso"]; if (modoInverso) { condicion1 = !condicion1; condicion2 = !condicion2; } Label10.Text = "" + (int)Session["movimientosJ1"]; Label18.Text = "" + (int)Session["movimientosJ2"]; fjugador1 = fichasJ1; fjugador2 = fichasJ2; Label8.Text = "" + fichasJ1; Label16.Text = "" + fichasJ2; Boolean movOtroJ = metodos.MovimientosPosibles(!(Boolean)Session["turno"], columnas, filas); metodos.Limpiar(columnas, filas); Boolean movTurnoAct = metodos.MovimientosPosibles((Boolean)Session["turno"], columnas, filas); if (fichasJ1 + fichasJ2 == columnas * filas || !movTurnoAct && !movOtroJ) { string resultado = null; if (condicion1) { string script = "alert('Gana Jugador 1!');"; ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, true); resultado = "Ganador"; } else if (condicion2) { string script = "alert('Gana Jugador 2!');"; ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, true); resultado = "Perdedor"; } else if (fichasJ1 == fichasJ2) { string script = "alert('Empate!');"; ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, true); resultado = "Empate"; } //partida = Datos(fjugador1, fjugador2); partida.resultado = resultado; //RegistrarPartida(partida); } else if (movTurnoAct) { } else if (!movTurnoAct) { Session["turno"] = !(Boolean)Session["turno"]; string script = "alert('No puedes mover! :c');"; ScriptManager.RegisterStartupScript(this, typeof(Page), "alerta", script, true); metodos.MovimientosPosibles((Boolean)Session["turno"], columnas, filas); } }