Ejemplo n.º 1
0
        private void BTNJugar_Click_1(object sender, EventArgs e)
        {
            lblGolesLocal.Visible = false;

            lblGolesVisitante.Visible = false;
            Equipo Local     = new Equipo();
            Equipo Visitante = new Equipo();

            Local.nombre     = comboBox1.Text;
            Visitante.nombre = comboBox2.Text;
            for (int i = 0; i < ListaEq.Count; i++)
            {
                if (Local.nombre == ListaEq[i].nombre)
                {
                    Local = ListaEq[i];
                }
                if (Visitante.nombre == ListaEq[i].nombre)
                {
                    Visitante = ListaEq[i];
                }
                if (Local.fuerza != null && Visitante.fuerza != null)
                {
                    break;
                }
            }
            if (Local.nombre == Visitante.nombre || Local.nombre == "" || Visitante.nombre == "")
            {
                MessageBox.Show("Por favor ingrese correctamente los equipos");
            }
            else
            {
                for (int i = 0; i < ListaEq.Count; i++)
                {
                    if (Local.nombre == ListaEq[i].nombre)
                    {
                        Local.fuerza = ListaEq[i].fuerza;
                    }
                    if (Visitante.nombre == ListaEq[i].nombre)
                    {
                        Visitante.fuerza = ListaEq[i].fuerza;
                    }
                }

                int gol1            = 0;
                int gol2            = 0;
                int num1            = 0;
                int num2            = 0;
                int fuerzalocal     = Convert.ToInt16(Local.fuerza);
                int fuerzavisitante = Convert.ToInt16(Visitante.fuerza);
                Convert.ToInt32(fuerzalocal);
                Convert.ToInt32(fuerzavisitante);
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        num1 = rand.Next(0, fuerzalocal);
                    }
                    if (i == 1)
                    {
                        num2 = rand.Next(0, fuerzavisitante);
                    }
                }
                Random goles = new Random();
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        gol1 = num1 / goles.Next(20, 40);
                    }
                    if (i == 1)
                    {
                        gol2 = num2 / goles.Next(20, 40);
                    }
                }
                Convert.ToString(gol1);
                Convert.ToString(gol2);
                MessageBox.Show(Local.nombre + " " + gol1 + "-" + gol2 + " " + Visitante.nombre, "Resultado parcial", MessageBoxButtons.OK);
                Convert.ToInt32(gol1);
                Convert.ToInt32(gol2);
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        num1 = rand.Next(0, fuerzalocal);
                    }
                    if (i == 1)
                    {
                        num2 = rand.Next(0, fuerzavisitante);
                    }
                }
                for (int i = 0; i < 2; i++)
                {
                    if (i == 0)
                    {
                        gol1 += num1 / goles.Next(20, 40);
                    }
                    if (i == 1)
                    {
                        gol2 += num2 / goles.Next(20, 40);
                    }
                }

                MessageBox.Show(Local.nombre + " " + gol1 + "-" + gol2 + " " + Visitante.nombre, "Resultado Final", MessageBoxButtons.OK);
                lblGolesLocal.Visible     = true;
                lblGolesVisitante.Visible = true;
                int    pos        = 275;
                Random Asignacion = new Random();
                int    IDgol      = 0;
                int    IDmin      = 99999;
                int    IDmax      = 0;
                for (int r = 0; r < Local.Jugadores.Count; r++)
                {
                    if (Local.Jugadores[r].ID < IDmin)
                    {
                        IDmin = Local.Jugadores[r].ID;
                    }
                    if (Local.Jugadores[r].ID > IDmax)
                    {
                        IDmax = Local.Jugadores[r].ID;
                    }
                }
                for (int i = 0; i < gol1; i++)
                {
                    nombregol      = new Label();
                    nombregol.Name = i.ToString();
                    //nombregol.Location = new Point(15, pos);
                    if (IDmin != 99999 && IDmax != 0)
                    {
                        IDgol = Asignacion.Next(IDmin, IDmax);
                        for (int q = 0; q < Local.Jugadores.Count; q++)
                        {
                            if (IDgol == Local.Jugadores[q].ID)
                            {
                                IDgol = q;
                                break;
                            }
                        }
                        nombregol.Text = Local.Jugadores[IDgol].nombre + " " + Local.Jugadores[IDgol].apellido;
                        this.dgvLocal.Rows.Add(nombregol.Text);
                        IDgol = 0;
                    }
                }
                IDmin = 99999;
                IDmax = 0;

                for (int zz = 0; zz < Visitante.Jugadores.Count; zz++)
                {
                    if (Visitante.Jugadores[zz].ID < IDmin)
                    {
                        IDmin = Visitante.Jugadores[zz].ID;
                    }
                    if (Visitante.Jugadores[zz].ID > IDmax)
                    {
                        IDmax = Visitante.Jugadores[zz].ID;
                    }
                }

                for (int i = 0; i < gol2; i++)
                {
                    nombregol      = new Label();
                    nombregol.Name = i.ToString();
                    //nombregol.Location = new Point(250, pos);


                    if (IDmin != 99999 && IDmax != 0)
                    {
                        IDgol = Asignacion.Next(IDmin, IDmax);
                        for (int aa = 0; aa < Visitante.Jugadores.Count; aa++)
                        {
                            if (IDgol == Visitante.Jugadores[aa].ID)
                            {
                                IDgol = aa;
                                break;
                            }
                        }
                        nombregol.Text = Visitante.Jugadores[IDgol].nombre + " " + Visitante.Jugadores[IDgol].apellido;
                        this.dgvVisitante.Rows.Add(nombregol.Text);
                        pos  += 30;
                        IDgol = 0;
                    }
                }
                IDmin = 99999;
                IDmax = 0;
            }
        }
Ejemplo n.º 2
0
        private void BTNJugar_Click_1(object sender, EventArgs e)
        {
            Equipo Loc = new Equipo();
            Equipo Vis = new Equipo();

            Loc = (Equipo)comboBox1.SelectedItem;
            Vis = (Equipo)comboBox2.SelectedItem;
            EquipoPartido Local     = new EquipoPartido();
            EquipoPartido Visitante = new EquipoPartido();

            Local.equipo     = Loc;
            Visitante.equipo = Vis;
            Local.Titulares  = Equipopart;
            EquipoPartido.AsignarTitularesRandom(Visitante);
            if (Local.equipo.nombre == Visitante.equipo.nombre || Local.equipo.nombre == "" || Visitante.equipo.nombre == "")
            {
                MessageBox.Show("Por favor ingrese correctamente los equipos");
            }
            else
            {
                if (Local.Titulares.Count != 11)
                {
                    EquipoPartido.AsignarTitularesRandom(Local);
                    MessageBox.Show("Al no poner 11 titulares, irá con formación al azar");
                }
                string formacion = "";
                foreach (Jugador j in Local.Titulares)
                {
                    formacion += j.apellido + ", ";
                }
                string formacion2 = "";
                foreach (Jugador j in Visitante.Titulares)
                {
                    formacion2 += j.apellido + ", ";
                }
                MessageBox.Show("Titulares de " + Local.equipo.nombre + ":" + Environment.NewLine + formacion + Environment.NewLine + "Titulares de " + Visitante.equipo.nombre + ":" + Environment.NewLine + formacion2);
                int    gol1            = 0;
                int    gol2            = 0;
                int    num1            = 0;
                int    num2            = 0;
                int    fuerzalocal     = Local.fuerza;
                int    fuerzavisitante = Visitante.fuerza;
                int    periodo         = 0;
                int    golanterior     = 0;
                int    golanterior2    = 0;
                int    IDgol           = 0;
                string goleador        = "";
                for (int i = 0; i < 6; i++)
                {
                    periodo++;
                    Estado.CalcularFuerza(ref num1, ref num2, rand, fuerzalocal, fuerzavisitante);
                    Gol.CalcularGoles(num1, num2, rand, ref gol1, ref gol2);
                    //timer1.Start();
                    if (gol1 != golanterior)
                    {
                        for (int l = 0; l < gol1 - golanterior; l++)
                        {
                            Gol.AsignarGol(rand, IDgol, ref goleador, Local);
                            Gol.AsignarMinuto(periodo, ref minutogol);
                            this.dgvLocal.Rows.Add(goleador, Convert.ToString(minutogol) + "'");
                            IDgol    = 0;
                            goleador = "";
                        }
                    }
                    if (gol2 != golanterior2)
                    {
                        for (int m = 0; m < gol2 - golanterior2; m++)
                        {
                            Gol.AsignarGol(rand, IDgol, ref goleador, Visitante);
                            Gol.AsignarMinuto(periodo, ref minutogol);
                            this.dgvVisitante.Rows.Add(goleador, Convert.ToString(minutogol) + "'");
                            IDgol    = 0;
                            goleador = "";
                        }
                    }
                    tiempopart     += Settings.Default.MinutoPeriodo;
                    lblminutos.Text = Convert.ToString(tiempopart) + "'";
                    lblgolloc.Text  = Convert.ToString(gol1);
                    lblgolvis.Text  = Convert.ToString(gol2);
                    golanterior     = gol1;
                    golanterior2    = gol2;
                    MessageBox.Show("Avanzar");
                    Thread.Sleep(200);
                }
            }
            int amarillas          = 0;
            int rojas              = 0;
            int amarillaslocal     = 0;
            int rojaslocal         = 0;
            int amarillasvisitante = 0;
            int rojasvisitante     = 0;

            Tarjeta.AsignacionTarjetas(rand, amarillas, rojas, ref amarillaslocal, ref amarillasvisitante, ref rojaslocal, ref rojasvisitante);
            MessageBox.Show("Cantidad de amarillas del local: " + amarillaslocal + Environment.NewLine + "Cantidad de rojas del local: " + rojaslocal);
            MessageBox.Show("Cantidad de amarillas del visitante: " + amarillasvisitante + Environment.NewLine + "Cantidad de rojas del visitante: " + rojasvisitante);
            //dgvLocal.Sort(dgvLocal.Columns(1), ListSortDirection.Ascending);
            BTNJugar.Enabled = false;
        }