public Juego JugarPiedra(Guid juegoGuid, string puntoId) { Juego juego = _juegoRepo.ObtenerJuego(juegoGuid); if (_puntoRepo.ExistePuntoEnTablero(puntoId, juego.Tablero) is false) { throw new FenixExceptionInvalidParameter("El punto no se encuentra en el tablero."); } Jugada jugada = new Jugada(juego); jugada.PonerPiedra(puntoId); GrupoCreador grupoCreador = new GrupoCreador(juego); List <Grupo> gruposNuevos = grupoCreador.AgruparPiedras(_puntoRepo.ObtenerPuntoPorId(puntoId)); juego.ActualizarGrupos(gruposNuevos); jugada.CambiarTurno(); _juegoRepo.GuardarCambios(); return(juego); }
private int CargarVariante(int posicionArray, string[] words, ref Variante variante, Jugada jugada) { var word = words[posicionArray]; if (EsJugadaBlanca(word)) { jugada.JugadaBlanco = ExtraerJugada(word); jugada.Estado = Estado.JugadaBlancaCargada; } else if (EsJugadaNegra(word)) { jugada.JugadaNegro = ExtraerJugada(word); jugada.Estado = Estado.JugadaNegraCargada; variante.Jugadas.Add(jugada); } else if (EsComentario(word)) { switch (jugada.Estado) { case Estado.JugadaBlancaSinCargar: { jugada.ComentarioPrevioBlanco += " " + word; break; } case Estado.JugadaBlancaCargada: { jugada.ComentarioPosteriorBlanco += " " + word; break; } case Estado.JugadaNegraCargada: { jugada.ComentarioPosteriorNegro += " " + word; break; } } } if (AbreVariante(word, jugada, variante.NumeroJugadaInicio)) { Variante nuevaVariante = new Variante(jugada.NumeroJugada); Jugada jugadaDeVariante = new Jugada(jugada.NumeroJugada); jugadaDeVariante.Estado = jugada.Estado; words[posicionArray] = EliminarAbridorVariante(word); int posicionesAvanzadas = CargarVariante(posicionArray, words, ref nuevaVariante, jugadaDeVariante); if (jugada.Estado == Estado.JugadaBlancaCargada) { if (jugada.VariantesBlanco != null) { jugada.VariantesBlanco.Add(nuevaVariante); } } posicionArray = posicionesAvanzadas; } if (CierraVariante(word)) { posicionArray++; return(posicionArray); } if (jugada.Estado == Estado.JugadaNegraCargada) { return(CargarVariante(posicionArray++, words, ref variante, new Jugada(jugada.NumeroJugada + 1))); } else { return(CargarVariante(posicionArray++, words, ref variante, jugada)); } }
private bool AbreVariante(string word, Jugada jugada, int numeroJugadaInicio) { throw new NotImplementedException(); }
public void GenerarJugada(Jugada jugada) { SqlConnection conexion = null; SqlTransaction transaccion = null; try { conexion = new SqlConnection(Conexion.Cnn); SqlCommand cmdAgregarJugada = new SqlCommand("AltaJugada", conexion); cmdAgregarJugada.CommandType = CommandType.StoredProcedure; SqlParameter retorno = new SqlParameter("@retorno", SqlDbType.Int); retorno.Direction = ParameterDirection.ReturnValue; cmdAgregarJugada.Parameters.AddWithValue("@documento", jugada.Jugador.Documento); cmdAgregarJugada.Parameters.AddWithValue("@fechaHoraSorteo", jugada.unSorteo.FechaHora); cmdAgregarJugada.Parameters.Add(retorno); //if (jugada.NumerosJugados.Count == 0) //{ // throw new Exception("La jugada ingresada no contiene números"); //} conexion.Open(); transaccion = conexion.BeginTransaction(); cmdAgregarJugada.Transaction = transaccion; int filasAfectadas = cmdAgregarJugada.ExecuteNonQuery(); if (filasAfectadas < 1) { if ((int)retorno.Value == -1) { throw new Exception("No existe el jugador"); } else if ((int)retorno.Value == -2) { throw new Exception("No hay un sorteo con fecha "); } else if ((int)retorno.Value == -3) { throw new Exception("El jugador ya realizó una jugada para este sorteo"); } else if ((int)retorno.Value == -4) { throw new Exception("Error al agregar la jugada"); } else { throw new Exception("No se pudo agregar la jugada"); } } else { jugada.Id = (int)retorno.Value; } AltaNumerosDeJugada(jugada, transaccion); transaccion.Commit(); } catch (Exception ex) { transaccion.Rollback(); throw new Exception(ex.Message); } finally { if (conexion != null) { conexion.Close(); } } }
/// <summary> /// Prepara la partida per començar /// </summary> public void PartidaNova() { int[] aux = null; for (int i = 0; i < subministraments.Count; i++) { if (subministraments.GetKey(i) != nameof(Jardins)) { subministraments.SetValueAt(i, 10); } else { subministraments[nameof(Jardins)] = Jugadors.Length > 2 ? 12 : 8; } } subministraments[nameof(Malediccio)] = Jugadors.Length == 2 ? 10 : Jugadors.Length == 3 ? 20 : 30; subministraments[nameof(Provincia)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Ducat)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Finca)] = Jugadors.Length > 2 ? 12 : 8; subministraments[nameof(Or)] = 30; subministraments[nameof(Plata)] = 40; subministraments[nameof(Coure)] = 60; for (int i = 0; i < Jugadors.Length; i++) { Jugadors[i].Reset(); jugadorActual = i; for (int j = 0; j < 7; j++) { AgafaCarta(typeof(Coure)); } for (int j = 0; j < 3; j++) { AgafaCarta(typeof(Finca)); } } Eliminades.Clear(); Jugada.Clear(); DinersExtra = 0; if (guanyadorsPartidaAnterior.Count == 0 || guanyadorsPartidaAnterior.Count == Jugadors.Length) { jugadorActual = MiRandom.Next(Jugadors.Length); } else if (guanyadorsPartidaAnterior.Count == 1) { jugadorActual = guanyadorsPartidaAnterior[0]; AvançaJugador(); } else if (guanyadorsPartidaAnterior.Count == 3 && Jugadors.Length == 4) { jugadorActual = QuatreJugadors.Except(guanyadorsPartidaAnterior).First(); } else { if (Jugadors.Length == 4) { aux = QuatreJugadors; } else if (Jugadors.Length == 3) { aux = TresJugadors; } aux = aux.Except(guanyadorsPartidaAnterior).ToArray(); aux.Desordena(); jugadorActual = aux[0]; } }
public void AddToDatabase(int loteria) { int pin = generator.Next(1000000, 10000000); string jugada_combinacion = ""; int puntos_combinacion = 0; using (IDbContextTransaction dbTran = Db.Database.BeginTransaction()) { try { Ticket ticket = new Ticket { Pin = pin, Anulado = false, Creado = DateTime.Now }; Db.Ticket.Add(ticket); Db.SaveChanges(); foreach (KeyValuePair <string, int> entry in previewDictionary) { Jugada jugada = new Jugada(); //if in the jugada table i already have el numero y la misma loteria y PARA LA MISMA FECHA if ((Db.Jugada.Any(j => j.Numero == entry.Key && j.LoteriaId == loteria && j.Fecha == DateTime.UtcNow.Date))) //If jugada exists { //jugada combinacion jugada_combinacion = entry.Key; //if the jugada length is 4 (pale) then throw the exception without checking anything if (entry.Key.Length > 2) { puntos_combinacion = 1; throw new Exception(); } var jugadaQuery = Db.Jugada.Where(j => j.LoteriaId == loteria && j.Numero == entry.Key && j.Fecha == DateTime.UtcNow.Date).FirstOrDefault(); int valorRepetido = jugadaQuery.Repetido; if (valorRepetido + entry.Value > 5) { puntos_combinacion = valorRepetido; throw new Exception(); //TODO show a message with the wrong values } //solo haz un update de la columna de repetido var valor = entry.Value; Db.Jugada.Where(j => j.LoteriaId == loteria && j.Numero == entry.Key && j.Fecha == DateTime.UtcNow.Date).Update(j => new Jugada { Repetido = j.Repetido + valor }); var query = Db.Jugada.Where(j => j.LoteriaId == loteria && j.Numero == entry.Key && j.Fecha == DateTime.UtcNow.Date).FirstOrDefault(); jugada.Id = query.Id; } else //If jugada doesn't exist { jugada.Numero = entry.Key; jugada.LoteriaId = loteria; jugada.Repetido = entry.Value; jugada.Fecha = DateTime.UtcNow.Date; jugada.Id = Guid.NewGuid(); Db.Jugada.Add(jugada); } TicketJugada ticketJugada = new TicketJugada { TicketId = ticket.Id, JugadaId = jugada.Id, Puntos = entry.Value }; Db.TicketJugada.Add(ticketJugada); } Db.SaveChanges(); PrintReceipt print = new PrintReceipt(previewDictionary, pin, ticket.Id, loteria); print.PrintTicket(); dbTran.Commit(); previewDictionary.Clear(); } catch (Exception) { MessageBox.Show($"No hay disponibilidad de la jugada {jugada_combinacion}, recuerde que el maximo son 5€(numeros)/1€(pales) y esa jugada ya tiene {puntos_combinacion}€ jugados"); dbTran.Rollback(); } } }
public void recibirJugada(Jugada jugada) { if (jugada.mensaje == "envido") { _estado = ESTADO.NEGOCIANDO_ENVIDO; _estadoEnvido = ESTADOENVIDO.ENVIDO; //resetea el truco _estadoTruco = ESTADOTRUCO.NULO; _player2.setTieneQuieroTruco(false); _player1.setTieneQuieroTruco(false); _envidosCantados++; _puntosEnvidoQuerido = 2 * _envidosCantados; _puntosEnvidoNoQuerido = _envidosCantados; } if (jugada.mensaje == "real envido") { _estado = ESTADO.NEGOCIANDO_ENVIDO; _estadoEnvido = ESTADOENVIDO.REAL; _estadoTruco = ESTADOTRUCO.NULO; _puntosEnvidoQuerido = 3 + (2 * _envidosCantados); _puntosEnvidoNoQuerido = 2 + _envidosCantados; } if (jugada.mensaje == "falta envido") { _estado = ESTADO.NEGOCIANDO_ENVIDO; _estadoEnvido = ESTADOENVIDO.FALTA; _estadoTruco = ESTADOTRUCO.NULO; _puntosEnvidoQuerido = _calcularTantosFaltaEnvido(); _puntosEnvidoNoQuerido = 1 + ((_estadoEnvido == ESTADOENVIDO.REAL) ? 3 : 0) + _envidosCantados; } if (jugada.mensaje == "truco") { _estado = ESTADO.NEGOCIANDO_TRUCO; _estadoTruco = ESTADOTRUCO.TRUCO; _puntosTrucoQuerido = 2; _puntosTrucoNoQuerido = 1; _player2.setTieneQuieroTruco(_player1.tienePalabra()); _player1.setTieneQuieroTruco(!_player1.tienePalabra()); } if (jugada.mensaje == "retruco") { _estado = ESTADO.NEGOCIANDO_TRUCO; _estadoTruco = ESTADOTRUCO.RETRUCO; //si se quiso el truco en primera mano este ya no esta disponible _estadoEnvido = ESTADOENVIDO.JUGADO; _puntosTrucoQuerido = 3; _puntosTrucoNoQuerido = 2; _player2.setTieneQuieroTruco(_player1.tienePalabra()); _player1.setTieneQuieroTruco(!_player1.tienePalabra()); } if (jugada.mensaje == "vale 4") { _estado = ESTADO.NEGOCIANDO_TRUCO; _estadoTruco = ESTADOTRUCO.VALE4; _puntosTrucoQuerido = 4; _puntosTrucoNoQuerido = 3; _player2.setTieneQuieroTruco(_player1.tienePalabra()); _player1.setTieneQuieroTruco(!_player1.tienePalabra()); } if (jugada.mensaje == "quiero") { if (_estado == ESTADO.NEGOCIANDO_ENVIDO) { _estadoEnvido = ESTADOENVIDO.JUGADO; _calcularEnvido(); } if (_estado == ESTADO.NEGOCIANDO_TRUCO) { _estadoEnvido = ESTADOENVIDO.JUGADO; } if (_player1.getPuntos() >= 30 || _player2.getPuntos() >= 30) { _estado = ESTADO.TERMINADA; } else { _estado = ESTADO.JUGANDO; } } if (jugada.mensaje == "no quiero") { if (_estado == ESTADO.NEGOCIANDO_TRUCO) { _estado = ESTADO.TERMINADA; if (_player1.tienePalabra()) { _player2.sumarPuntos(_puntosTrucoNoQuerido); } else { _player1.sumarPuntos(_puntosTrucoNoQuerido); } } else { // Si se está engociando envido _estadoEnvido = ESTADOENVIDO.JUGADO; _estado = ESTADO.JUGANDO; if (_player1.tienePalabra()) { _player2.sumarPuntos(_puntosEnvidoNoQuerido); } else { _player1.sumarPuntos(_puntosEnvidoNoQuerido); } } } if (jugada.mensaje == "irse al mazo") { if (_estado == ESTADO.JUGANDO) { _estado = ESTADO.TERMINADA; if (_player1.tienePalabra()) { _player2.sumarPuntos(_puntosTrucoNoQuerido); } else { _player1.sumarPuntos(_puntosTrucoNoQuerido); } } } if (jugada.mensaje == "carta") { _player1.setJugoTurno(_player1.tieneTurno()); _player2.setJugoTurno(_player2.tieneTurno()); // Verifico si alguno de los jugadores ya ganó la mano if (_calcularTurnosGanados(_player1, _player2) >= 2) { _estado = ESTADO.TERMINADA; _player1.sumarPuntos(_puntosTrucoQuerido); } else { if (_calcularTurnosGanados(_player2, _player2) >= 2) { _estado = ESTADO.TERMINADA; _player2.sumarPuntos(_puntosTrucoQuerido); } else { // Si ambos jugadores ya tiraron las 3 cartas, se termina la mano // Este caso solo se da si empardaron las 3 manos, si es así se lleva los puntos el mano if (_player1.getCantCartasMesa() == 3 && _player2.getCantCartasMesa() == 3) { _estado = ESTADO.TERMINADA; if (_player1.esMano()) { _player1.sumarPuntos(_puntosTrucoQuerido); } else { _player2.sumarPuntos(_puntosTrucoQuerido); } } else { // Se verifica si la carta tirada mata, no mata o emparda a la anterior del oponente if ((_player1.getUltimaCartaJugada() != null && _player2.getUltimaCartaJugada() != null) && (_player1.getCantCartasMesa() == _player2.getCantCartasMesa())) { if ((_player1.tieneTurno() && _player1.getUltimaCartaJugada().mata(_player2.getUltimaCartaJugada()) == 1) || (_player2.tieneTurno() && _player2.getUltimaCartaJugada().mata(_player1.getUltimaCartaJugada()) == 1)) { _estadoCartas = ESTADOCARTAS.MATA; } else { if ((_player1.tieneTurno() && _player1.getUltimaCartaJugada().mata(_player2.getUltimaCartaJugada()) == -1) || (_player2.tieneTurno() && _player2.getUltimaCartaJugada().mata(_player1.getUltimaCartaJugada()) == -1)) { _estadoCartas = ESTADOCARTAS.NOMATA; } else { _estadoCartas = ESTADOCARTAS.EMPARDA; } } } else { _estadoCartas = ESTADOCARTAS.NOMATA; } } } } } _siguienteJugada(jugada); }
/// <summary> /// Al apretar el botn aceptar se efectua una compra si los datos estan correctos y se genera la nueva informacion del /// usuario /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAceptar_Click(object sender, EventArgs e) { try { string seleccionado; this.participante = Casino.BuscarJugador(this.ca, txtBoxIDJugador.Text); if (this.participante == null) { this.participante = new Jugador(txtBoxIDJugador.Text); } try { if (int.Parse(txtBoxCantidadMonedas.Text) > 0) { seleccionado = cmbBoxTipoMoneda.SelectedItem.ToString(); int cant = int.Parse(txtBoxCantidadMonedas.Text); this.primera = new Jugada(participante); if (seleccionado != "PLUSCHANCESTICKET") { Moneda moni = null; switch (cmbBoxTipoMoneda.SelectedItem) { case ETipoMoneda.bronce: moni = new Moneda(Moneda.SacarPrecio(ETipoMoneda.bronce), cant, ETipoMoneda.bronce, Moneda.SacarGanancia(ETipoMoneda.bronce));//gana 3 veces mas participante += moni; break; case ETipoMoneda.oro: moni = new Moneda(Moneda.SacarPrecio(ETipoMoneda.oro), cant, ETipoMoneda.oro, Moneda.SacarGanancia(ETipoMoneda.oro));//gana 3 veces mas participante += moni; break; case ETipoMoneda.plata: moni = new Moneda(Moneda.SacarPrecio(ETipoMoneda.plata), cant, ETipoMoneda.plata, Moneda.SacarGanancia(ETipoMoneda.plata));//gana 3 veces mas participante += moni; break; } this.primera.Varianza = Jugada.CalcularVarianza(moni, cant, ETipoTransaccion.compra); this.DialogResult = DialogResult.OK; } else { try { BoletoChances boletonew = new BoletoChances(cant); this.participante += boletonew; this.primera.Varianza = BoletoChances.GastoBoleto(cant, Moneda.SacarPrecio(ETipoMoneda.bronce)); this.DialogResult = DialogResult.OK; } catch (insuficienteParaBoletoException) { throw new insuficienteParaBoletoException($" Usted tiene en total {this.participante.CantidadMonedasSegunTipo(ETipoMoneda.bronce)} monedas de bronce"); } } this.participante.Saldo = participante.SacarSaldo(participante.Billetera); this.primera.Movimiento = ETipoTransaccion.compra; this.Close(); } else { throw new cantidadInvalidaException(); } } catch (FormatException) { throw new cantidadInvalidaException(); } } catch (insuficienteParaBoletoException ex) { MessageBox.Show(ex.Message); } catch (dniInvalidoException ex) { MessageBox.Show(ex.Message); } catch (cantidadInvalidaException ex) { MessageBox.Show(ex.Message); } }
void moverFicha(Jugada jugada) { string id; bool b = true; // Seleccionar la ficha a mover if (selected == null) { for (int i = 1; i <= 2 && b; i++) { for (int j = 1; j <= 5 && b; j++) { id = "P" + i + "F" + j; if (GameObject.FindWithTag(id) != null && GameObject.FindWithTag(id).GetComponent<MatrixAttributes>().x == jugada.fichaX && GameObject.FindWithTag(id).GetComponent<MatrixAttributes>().y == jugada.fichaY) { selectDeselectPiece(id); b = false; } } } } moverFicha(jugada.fichaX, jugada.fichaY, jugada.destinoX, jugada.destinoY); }
public void realizarJugada(Jugada jugada) { _manoActiva.recibirJugada(jugada); }
private int max(Estado estado, Equipo equipo, ref List<Jugada> listaJugadas, int alfa, int beta, int profundidad) { // Retornar si es un nodo hoja if (profundidad == 0 || estado.esGol()) { return estado.valorar(); } // Generar sucesores int valor = -infinito; List<Jugada> jugadas = new List<Jugada>(); // Ficha for (int j = 0; j < estado.cantidadFichas; j++) { // Distancia for (int dj = 1; dj <= 2; dj++) { // Direccion Jugador for (int jx = -1; jx <= 1; jx++) { for (int jy = -1; jy <= 1; jy++) { if (jx == 0 && jy == 0) { continue; } int djx = estado.jugadores[j].x + jx * dj; int djy = estado.jugadores[j].y + jy * dj; // Validar el movimiento if (!validarMovimiento(estado.jugadores[j].x, estado.jugadores[j].y, djx, djy, false)) { continue; } // Mover al jugador Jugada jugadaJugador = new Jugada(estado.jugadores[j].x, estado.jugadores[j].y, djx, djy); jugadas.Add(jugadaJugador); estado.mover(equipo, jugadaJugador, false); // En caso de ser un pase de pelota, iterar en base a esta if (estado.pelota.tieneInfluencia(equipo, true)) { bool terminar; int m = iterarPelotaMax(estado, equipo, ref listaJugadas, ref jugadas, ref valor, ref alfa, ref beta, profundidad, out terminar); if (terminar) { estado.mover(equipo, jugadaJugador, true); jugadas.Remove(jugadaJugador); return m; } } // Si no se hizo un pase, bajar un nivel else { int m = min(estado, proximoEquipo(equipo), alfa, beta, profundidad - 1); if (m > valor) { valor = m; // Si se esta buscando la lista de jugadas, hacer una copia de las jugadas en su estado actual if (listaJugadas != null) { listaJugadas = new List<Jugada>(jugadas); } } if (valor >= beta) { estado.mover(equipo, jugadaJugador, true); jugadas.Remove(jugadaJugador); return valor; } else if (valor > alfa) { alfa = valor; } } // Retornar el jugador estado.mover(equipo, jugadaJugador, true); jugadas.Remove(jugadaJugador); } } } } return valor; }
private int iterarPelotaMax(Estado estado, Equipo equipo, ref List<Jugada> listaJugadas, ref List<Jugada> jugadas, ref int valor, ref int alfa, ref int beta, int profundidad, out bool terminar) { terminar = false; for (int dp = 1; dp <= 4; dp++) { // Direccion Pelota for (int px = -1; px <= 1; px++) { for (int py = -1; py <= 1; py++) { if (px == 0 && py == 0) { continue; } int dpx = estado.pelota.x + px * dp; int dpy = estado.pelota.y + py * dp; // Validar el movimiento if (!validarMovimiento(estado.pelota.x, estado.pelota.y, dpx, dpy, false)) { continue; } // Mover la pelota pases += 1; Jugada jugadaPelota = new Jugada(estado.pelota.x, estado.pelota.y, dpx, dpy); jugadas.Add(jugadaPelota); estado.mover(equipo, jugadaPelota, false); // En caso de no poder seguir jugando, bajar un nivel if (!estado.pelota.tieneInfluencia(equipo, true) || jugadas.Count >= 5) { int m = min(estado, proximoEquipo(equipo), alfa, beta, profundidad - 1); if (m > valor) { valor = m; // Si se esta buscando la lista de jugadas, hacer una copia de las jugadas en su estado actual if (listaJugadas != null) { listaJugadas = new List<Jugada>(jugadas); } } if (valor >= beta) { terminar = true; pases -= 1; estado.mover(equipo, jugadaPelota, true); jugadas.Remove(jugadaPelota); return valor; } else if (valor > alfa) { alfa = valor; } } // Sino seguir jugando else { int m = iterarPelotaMax(estado, equipo, ref listaJugadas, ref jugadas, ref valor, ref alfa, ref beta, profundidad, out terminar); } // Retornar la pelota pases -= 1; estado.mover(equipo, jugadaPelota, true); jugadas.Remove(jugadaPelota); } } } return valor; }
public void mover(Equipo turno, Jugada jugada, bool deshacer) { int fichaX, fichaY, destinoX, destinoY; // Definir el sentido del movimiento if (deshacer) { fichaX = jugada.destinoX; fichaY = jugada.destinoY; destinoX = jugada.fichaX; destinoY = jugada.fichaY; } else { fichaX = jugada.fichaX; fichaY = jugada.fichaY; destinoX = jugada.destinoX; destinoY = jugada.destinoY; } // Realizar los cambios de posicion setFicha(destinoX, destinoY, board[fichaX, fichaY].ficha); setFicha(fichaX, fichaY, TipoFicha.Vacio); // Actualizar la referencia // Pelota if (board[destinoX, destinoY].ficha == TipoFicha.Pelota) { pelota = board[destinoX, destinoY]; } // Jugador else { for (int i = 0; i < cantidadFichas; i++) { if (equipo == turno && jugadores[i].x == fichaX && jugadores[i].y == fichaY) { jugadores[i] = board[destinoX, destinoY]; } else if (equipo != turno && oponentes[i].x == fichaX && oponentes[i].y == fichaY) { oponentes[i] = board[destinoX, destinoY]; } } } }
public void Inicializar() { _juego = new Juego(Tablero.nueveXnueve); _jugada = new Jugada(_juego); }
public MensajeResultadoMano(int p, int po, Jugada j) { this.puntos = p; this.puntosOponente = po; this.jugadaAnterior = j; }
public void Mover(Jugada jug) { estadoActual = Mover(EstadoActual, jug); estadoActual.Nivel = 0; }
public void crearLaberinto(int numCasillas) { int i, j, n; Jugada[] jugadasPosibles = new Jugada[this.ancho * this.alto]; int aux; int contJugadas = 0; int[] contactos = new int[4]; int numContactos = 0; for (i = 0; i < ancho; i++) { for (j = 0; j < alto; j++) { laberinto [i, j] = -1; jugadasPosibles [contJugadas] = new Jugada(); jugadasPosibles [contJugadas].fila = i; jugadasPosibles [contJugadas].columna = j; contJugadas++; } } aux = Random.Range(0, contJugadas); laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] = 1111; for (n = 1; n < numCasillas; n++) { contJugadas = 0; for (i = 0; i < ancho; i++) { for (j = 0; j < alto; j++) { if (laberinto [i, j] == -1) { numContactos = 0; if (i > 0 && laberinto [i - 1, j] != -1) { contactos [numContactos] = 4; numContactos++; } if (j > 0 && laberinto [i, j - 1] != -1) { contactos [numContactos] = 3; numContactos++; } if (i < ancho - 1 && laberinto [i + 1, j] != -1) { contactos [numContactos] = 2; numContactos++; } if (j < alto - 1 && laberinto [i, j + 1] != -1) { contactos [numContactos] = 1; numContactos++; } if (numContactos > 0) { aux = Random.Range(0, numContactos); jugadasPosibles [contJugadas].fila = i; jugadasPosibles [contJugadas].columna = j; jugadasPosibles [contJugadas].direccion = contactos[aux]; contJugadas++; } } } } aux = Random.Range(0, contJugadas); laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] = 1111; switch (jugadasPosibles [aux].direccion) { case 1: laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] -= 1000; laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna + 1] -= 10; break; case 2: laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] -= 100; laberinto [jugadasPosibles [aux].fila + 1, jugadasPosibles [aux].columna] -= 1; break; case 3: laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] -= 10; laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna - 1] -= 1000; break; case 4: laberinto [jugadasPosibles [aux].fila, jugadasPosibles [aux].columna] -= 1; laberinto [jugadasPosibles [aux].fila - 1, jugadasPosibles [aux].columna] -= 100; break; } } for (i = 0; i < ancho; i++) { for (j = 0; j < alto; j++) { if (laberinto [i, j] != -1) { if (i < ancho - 1 && laberinto [i + 1, j] != -1) { aux = Random.Range(0, 5); if (aux < 2 && laberinto [i + 1, j] % 1 == 1) { laberinto [i, j] -= 100; laberinto [i + 1, j] -= 1; } } if (j < alto - 1 && laberinto [i, j + 1] != -1) { aux = Random.Range(0, 5); if (aux < 2 && (laberinto [i, j + 1] / 10) % 10 == 1) { laberinto [i, j] -= 1000; laberinto [i, j + 1] -= 10; } } } } } crearCasillas(); guardarCopia(); }
static void Main(string[] args) { Casino casi = new Casino();//jugadores y jugadas BoletoChances boleto = new BoletoChances(2); List <Moneda> monedas = new List <Moneda>(); Moneda moni = new Moneda(34, 6, ETipoMoneda.bronce, 2); Moneda moni2 = new Moneda(50, 2, ETipoMoneda.plata, 4); monedas += moni; monedas += moni; if (monedas.Count == 1) { Console.WriteLine("No se agregó"); } monedas += moni2; if (monedas.Count > 1) { Console.WriteLine("Se agregó"); } Jugador uno = new Jugador(11, 100, boleto, monedas); Jugador dos = new Jugador(12, 3000, boleto, monedas); Jugador tres = new Jugador(13, 3000, boleto, monedas); casi += dos; casi += uno; if (Casino.BuscarJugador(casi, uno.DNI.ToString()) != null) { Console.WriteLine($"{uno.DNI.ToString()} se encuentra en el casino"); } if (Casino.BuscarJugador(casi, tres.DNI.ToString()) == null) { Console.WriteLine($"{tres.DNI.ToString()} no se encuentra en el casino"); } Jugada juego = new Jugada(uno, -20, ETipoTransaccion.pierde); Console.WriteLine("----------------------------------------------"); Console.WriteLine(""); Console.WriteLine("Billetera de Jugadores: "); foreach (Jugador item in casi.Jugadores) { Console.WriteLine(item.DNI); Console.WriteLine(item.ToString()); Console.WriteLine(""); } casi += juego; Console.WriteLine("Partidas: "); foreach (Jugada item in casi.Jugadas) { Console.WriteLine(item.ToString()); } Console.ReadKey(); }
private void UserControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (jugador != null) { Jugada jugada = new Jugada(posX, posY, jugador.misBarcos[0].celdasDelBarco[0].dueño, -2); if (puedeEnviarJugada()) { Jugador.Enviar(jugador.cliente, jugada); int n = (int)Jugador.Recibir_Objeto(jugador.cliente); // retorna quién lo atacó MW.ultimoDisparo = DateTime.Now; if (n == 0) { color = Brushes.AliceBlue; cambiarC(jugada); if (MW.delay <= 5) // lo maximo que puede esperar es 5 segundos !! { MW.delay += 1; } MW.canonConBarra.progressBar1.Maximum = MW.delay; } else if (n < 10) { color = ataqueAotro[n]; cambiarColor(color); MW.delay = 2; MW.canonConBarra.progressBar1.Maximum = MW.delay; } else if (n > 10) { color = dic[n - 10]; cambiarColor(color); MW.delay = 2; MW.canonConBarra.progressBar1.Maximum = MW.delay; } } } else if (servidor != null) { Jugada jugada = new Jugada(posX, posY, 1, -2); if (puedeEnviarJugada()) { MW.ultimoDisparo = DateTime.Now; servidor.jugadasServidor.Add(jugada); Jugada jug = servidor.jugadasServidor.ElementAt(0); int n = servidor.p.revisarJugada(jug); //me avisa quien lo atacó //servidor.p.dpsDeRevisarJugada(); if (n != 0 && n < 10) //&& jugada.atacoAntes==-2 { //if (this.color == Brushes.Transparent) //{ color = ataqueAotro[n]; cambiarColor(color); //} MW.delay = 2; MW.canonConBarra.progressBar1.Maximum = MW.delay; servidor.listas.ElementAt(n - 1).Add(jug); } else if (n > 10) { color = dic[n - 10]; cambiarColor(color); MW.delay = 2; MW.canonConBarra.progressBar1.Maximum = MW.delay; } else { if (MW.delay <= 5) // lo maximo que puede esperar es 5 segundos !! se alenta cuando hay muchos conectadoos { MW.delay += 1; } MW.canonConBarra.progressBar1.Maximum = MW.delay; } servidor.jugadasServidor.Remove(servidor.jugadasServidor.ElementAt(0)); } } }
private void _pedirJugadas(Jugada jugadaAnterior) { _pedirJugada(_player1, _player2, jugadaAnterior); _pedirJugada(_player2, _player1, jugadaAnterior); }
public void Inicializar() { _jugada = new Jugada(); }
/// <summary> /// al apretar Jugar en este form se abrira un form ruleta y se armara la partida y los nuevos datos del jugador /// segun si el random perdio o gano. solo se podra abrir un form de ruleta si no existe uno ya corriendo y /// si todos los datos son correctos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnJugar_Click(object sender, EventArgs e) { if (!invoked) { try { if ((this.victima = Casino.BuscarJugador(this.ca, txtBoxIDAJugar.Text)) != null) { try { int cantidadJ; cantidadJ = int.Parse(txtCantidadAJugar.Text); if (cantidadJ < 0) { throw new FormatException(); } ETipoMoneda money = (ETipoMoneda)cmbBoxAJugar.SelectedItem; int ganancia = Moneda.SacarGanancia(money); if (this.victima.CantidadMonedasSegunTipo(money) >= cantidadJ) { if ((rdoButtonBoleto.Checked && this.victima.Boletos.Cantidad > 0) || rdoButtonBoleto.Checked == false) { /*base del form*/ this.ruleta = new FormRule(); this.ruleta.frenacion += spinStop; this.invoked = true;//si ya se abrio una ruleta y no se cerro de ninguna forma no se puede generar otro form ruleta.Show(); this.InicioThread(); /**/ if ((rdoButtonBoleto.Checked && this.victima.Boletos.Cantidad > 0)) { BoletoChances apuesto = new BoletoChances(1); this.victima -= apuesto; } Moneda apostada = new Moneda(Moneda.SacarPrecio(money), cantidadJ, money, ganancia); this.segunda = new Jugada(this.victima); this.winLo = ganoperdio.Next(0, 50); if (this.winLo > 35)/*15 veces mas de perder que de ganar*/ { this.segunda.Varianza = Jugada.CalcularVarianza(apostada, cantidadJ, ETipoTransaccion.gana); apostada.Cantidad = apostada.Cantidad * ganancia; this.victima += apostada; this.segunda.Movimiento = ETipoTransaccion.gana; } else { this.segunda.Movimiento = ETipoTransaccion.pierde; this.segunda.Varianza = Jugada.CalcularVarianza(apostada, cantidadJ, ETipoTransaccion.pierde); this.victima -= apostada; } this.victima.Saldo = this.victima.SacarSaldo(this.victima.Billetera); } else { MessageBox.Show("No le alcanzan los boletos"); } } else { MessageBox.Show("No tiene las monedas suficientes para jugar"); } } catch (FormatException) { throw new cantidadInvalidaException(); } } else { MessageBox.Show("No se encuentra ese dni en la lista de jugadores disponibles"); } }
private Igu() { jugada = new Jugada(); tablero = new char[32]; }