public void IniciarJuego() { //valores iniciales del juego flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; lblMensaje.Visible = false; Oportunidades = 7;//fallo btnIniciarJuego.Image = Properties.Resources.btn_comenzar; Palabras = new string[] { "rojo", "azul", "negro", "blanco", "amarillo", "verde", "rosado", "morado", "cafe", "gris" }; Alfabeto = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ".ToCharArray(); //palabra aletoria-adivinar Random random = new Random(); int IndicePalabraSeleccionada = random.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[IndicePalabraSeleccionada].ToUpper().ToCharArray(); PalabrasAdivinadas = PalabraSeleccionada; //ciclo que calga el alfabeto en el flow layout foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 60; btnLetra.Height = 40; btnLetra.Click += Compara;//cuando el ususario selecciones cualquier letra entrara en la funcion btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabra.Controls.Clear(); //ciclo que carga el alfabeto en un folwlayout for (int IndiceValorLetra = 0; IndiceValorLetra < PalabraSeleccionada.Length; IndiceValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[IndiceValorLetra].ToString(); Letra.Width = 46; Letra.Height = 80; Letra.ForeColor = Color.Purple; Letra.Text = "-"; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + IndiceValorLetra.ToString(); flPalabra.Controls.Add(Letra); } }
public void IniciarJuego() { flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; picAhorcado.Image = null; lblMensaje.Visible = false; Oportunidades = 0; btnIniciarJuego.Image = Properties.Resources.Jugando; Palabras = new string[] { "mango", "habichuela", "guineo", "yuca", "batata", "platano", "hevo", "brocolis", "yautia", "tigre", "leon", "yena", "cebra", "cocodrillo", "tiburon", "raton", "juguar" }; Alfabeto = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ".ToCharArray(); Random random = new Random(); int indicepalabrasseleccionada = random.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[indicepalabrasseleccionada].ToUpper().ToCharArray(); PalabrasAdivinadas = PalabraSeleccionada; foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 60; btnLetra.Height = 40; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabra.Controls.Clear(); for (int IndiceValorLetra = 0; IndiceValorLetra < PalabraSeleccionada.Length; IndiceValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[IndiceValorLetra].ToString(); Letra.Width = 50; Letra.Height = 90; Letra.ForeColor = Color.Purple; Letra.Text = "-"; Letra.Font = new Font(Letra.Font.Name, 42, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + IndiceValorLetra.ToString(); Letra.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Acertijo)); flPalabra.Controls.Add(Letra); } }
public void IniciarJuego() { flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; picAhorcado.Image = null; lblMensaje.Visible = false; Oportunidades = 0; btnIniciarJuego.Image = Properties.Resources.Jugando; Palabras = new string[] { "mango", "habichuela", "guineo" }; Alfabeto = "abcdefghijklmnñopqrstuvwxyz".ToCharArray(); Random random = new Random(); int indicepalabrasseleccionada = random.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[indicepalabrasseleccionada].ToUpper().ToCharArray(); PalabrasAdivinadas = PalabraSeleccionada; foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 60; btnLetra.Height = 40; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabra.Controls.Clear(); for (int IndiceValorLetra = 0; IndiceValorLetra < PalabraSeleccionada.Length; IndiceValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[IndiceValorLetra].ToString(); Letra.Width = 46; Letra.Height = 80; Letra.ForeColor = Color.Purple; Letra.Text = "-"; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + IndiceValorLetra.ToString(); Letra.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.Acertijo)); flPalabra.Controls.Add(Letra); } }
public void IniciarJuego() { //MUSICA SoundPlayer sonido = new SoundPlayer(); sonido.Stream = Properties.Resources.Team_America_Theme_Song__online_audio_converter_com_; sonido.PlayLooping(); //Aqui iniciaremos flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; picAhorcado1.Image = null; picAhorcado2.Image = null; picAhorcado3.Image = null; picAhorcado4.Image = null; picAhorcado5.Image = null; picAhorcado7.Image = null; picAhorcado6.Image = null; picAhorcado8.Image = null; MensajeInicio.Visible = false; MensajeMuerte.Visible = false; Oportunidades = 0; Palabras = new String[] { "machista", "racista", "ordenmundial", "iluminati", "china", "cincog", "abuso", "manipulacion", "mentira", "bilgates", "fredyepstein", "alienigena", }; Alfabeto = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ".ToArray(); //palabra aleatoria - adivinar Random random = new Random(); int IndicePalabraSeleccionada = random.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[IndicePalabraSeleccionada].ToUpper().ToArray(); PalabrasAdivinadas = PalabraSeleccionada; //Ciclo que carga el alfabeto en un flowlayout -- > flFichasDeJuego foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Height = 40; btnLetra.Width = 60; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); if (opcionElegida == 2) { Console.WriteLine("LLega aqui!!!!"); Char[] destapa = new Char[3]; for (int i = 0; i < opcionElegida; i++) { destapa[i] = PalabraSeleccionada[i]; //las dos letras estan aqui, como se desactivan los botones y como se muestran las letras Console.WriteLine(destapa[i]); Console.WriteLine("LLega aqui!!!!"); } if (destapa[0].ToString() == btnLetra.Text) { Console.WriteLine("Entra"); btnLetra.BackColor = Color.White; btnLetra.Enabled = false; } if (destapa[1].ToString() == btnLetra.Text) { Console.WriteLine("Entra"); btnLetra.BackColor = Color.White; btnLetra.Enabled = false; } //ifbtnLetra.Name } } flPalabra.Controls.Clear(); //Ciclo que agrega la palabra en un flowlayout (palabra a adivinar) for (int i = 0; i < PalabraSeleccionada.Length; i++) { Letra = new Button(); Letra.Tag = PalabraSeleccionada[i].ToString(); Letra.Width = 46; Letra.Height = 80; Letra.ForeColor = Color.Black; Letra.Text = "-"; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + i.ToString(); flPalabra.Controls.Add(Letra); if (opcionElegida == 2) { Console.WriteLine("LLega aqui!!!!"); Char[] destapa = new Char[3]; for (int x = 0; x < opcionElegida; x++) { destapa[x] = PalabraSeleccionada[x]; //las dos letras estan aqui, como se desactivan los botones y como se muestran las letras Console.WriteLine(destapa[x]); Console.WriteLine("LLega aqui!!!!"); } if (destapa[0] == PalabraSeleccionada[i]) { Console.WriteLine("Entra"); Letra.Text = destapa[0].ToString(); Console.WriteLine(Letra.Text); } if (destapa[1] == PalabraSeleccionada[i]) { Console.WriteLine("Entra"); Letra.Text = destapa[1].ToString(); } } //--------------------------------------------------------------------------------------------------------------------------------- if (opcionElegida == 1) { Console.WriteLine("LLega aqui!!!!"); Char[] destapa = new Char[3]; for (int x = 0; x < opcionElegida; x++) { destapa[x] = PalabraSeleccionada[x]; //las dos letras estan aqui, como se desactivan los botones y como se muestran las letras Console.WriteLine(destapa[x]); Console.WriteLine("LLega aqui!!!!"); } if (destapa[0] == PalabraSeleccionada[i]) { Console.WriteLine("Entra"); Letra.Text = destapa[0].ToString(); Console.WriteLine(Letra.Text); } } } void Compara(object sender, EventArgs e) { MensajeInicio.Visible = true; //boton presionado se desactiva bool encontrado = false; Button btn = (Button)sender; btn.BackColor = Color.White; btn.Enabled = false; //compara la letra seleccionada con las letras de la palabra for (int i = 0; i < PalabrasAdivinadas.Length; i++) { char charAux = '9'; charAux = Char.Parse(btn.Text); if (PalabrasAdivinadas[i] == Char.Parse(btn.Text)) { //si existe la letra actualiza la palabra agregando el valor correspondiente Button tbx = this.Controls.Find("Adivinado" + i, true).FirstOrDefault() as Button; PalabrasAdivinadas[i] = '-'; tbx.Text = charAux.ToString(); encontrado = true; } } //verifica si todas las letras de la palabra estan destapadas bool Ganaste = false; for (int i = 0; i < PalabrasAdivinadas.Length; i++) { //Si el usuario tiene letras pendientes por destapar se cambia el estatus if (PalabrasAdivinadas[i] != '-') { Ganaste = true; } } //Si el estatus de la variable no cambia quiere decir el usuario gano if (!Ganaste) { MessageBox.Show("Has Ganado Maquina!!"); /* btnIniciarJuego.Image = Properties.Resources.btnStart;*/ //--------------Aqui poner foto diferente------------------ } //si no se encuentra niguna letra de la palabra if (!encontrado) { Oportunidades = Oportunidades + 1; if (Oportunidades == 1) { picAhorcado1.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\pie.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 2) { picAhorcado2.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\Palo1.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 3) { picAhorcado3.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\Palo2.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 4) { picAhorcado4.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\Palo3.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 5) { picAhorcado5.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\orca.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 6) { picAhorcado6.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\cuerpo.jpg"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 7) { picAhorcado7.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\pies.jpg"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } if (Oportunidades == 8) { picAhorcado8.ImageLocation = @"C:\Users\Ras\source\repos\Ahorcado\ArchivosMultimedia\cara donald2.png"; sonido.Stream = Properties.Resources.Homer_Simpson_Doh_sound_effect; sonido.Play(); } //picAhorcado.Image = Image.FromFile("F:\ahorcado\ahorcado8.png"); } //se han acabado las oportunidades(mostrar mensaje) if (Oportunidades == 8) { MensajeMuerte.Visible = true; //Muestra la palabra que el usuario intentaba adivinar for (int i = 0; i < PalabraSeleccionada.Length; i++) { Button btnLetra = this.Controls.Find("Adivinado" + i, true).FirstOrDefault() as Button; btnLetra.Text = btnLetra.Tag.ToString(); } sonido.Stream = Properties.Resources.game_over_1_gameover; sonido.Play(); //desactiva las fichas y cambia el boton de reinicio flFichasDeJuego.Enabled = false; // btnIniciarJuego.Image = Properties.Resources.btnStart; -----------------------------------------aqui-------------------------- } } }
public void StartGame() { readFile(); flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; picAhorcado.Image = null; lblMensajeLose.Visible = false; lblMensajeWin.Visible = false; Oportunidades = 0; btnIniciarJuego.Image = Properties.Resources.Jugando; //Palabras = new string[] { "Computer", "Laptop", "Keyboard", "Network" , "Password" }; Alfabeto = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); //Crear Palabra aleatoria Random ramdom = new Random(); int IndicePalabrasSeleccionadas = ramdom.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[IndicePalabrasSeleccionadas].ToUpper().ToCharArray(); PalabrasAdivinadas = PalabraSeleccionada; //Cargar Alfabeto foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 60; btnLetra.Height = 40; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.MediumPurple; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabra.Controls.Clear(); //Colocamos la palabra seleccionada. for (int ValorLetra = 0; ValorLetra < PalabraSeleccionada.Length; ValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[ValorLetra].ToString(); Letra.Width = 46; Letra.Height = 80; Letra.ForeColor = Color.MediumPurple; Letra.Text = "_"; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = FlatStyle.Flat; Letra.Name = "Adivinado" + ValorLetra.ToString();; flPalabra.Controls.Add(Letra); } //Rellenamos un hueco de para darle pistas al usuario. Random ramdomLetra = new Random(); int indice = ramdomLetra.Next(0, Palabras.Length); Button letra1 = this.Controls.Find("Adivinado" + indice, true).FirstOrDefault() as Button; letra1.Text = PalabrasAdivinadas[indice].ToString(); PalabrasAdivinadas[indice] = '-'; //Añdir otra letra descubierta. int indice2 = ramdomLetra.Next(0, Palabras.Length); Button letra2 = this.Controls.Find("Adivinado" + indice2, true).FirstOrDefault() as Button; letra2.Text = PalabrasAdivinadas[indice2].ToString(); PalabrasAdivinadas[indice2] = '-'; }
public void IniciarJuego() { //valores iniciales del juego flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; //lblMensaje.Visible=false; Oportunidades = 0; //fallo sas = 8; //btnIniciarJuego.Image=Properties.Resources." "; Palabras = new string[, ] { { "Y si perezco, que perezca.", "Ester" }, { "¿Hasta cuándo claudicaréis vosotros entre dos pensamientos?", "Elias" }, { "Muera yo la muerte de los rectos.", "Balaam" }, { "Sol, detente en Gabaón; Y tú, luna, en el valle de Ajalón.", "Josue" }, { "¿Recibiremos de Dios el bien, y el mal no lo recibiremos?", "Job" }, { "Han visto mis ojos al Rey, Jehová de los ejércitos.", "Isaias" }, { "Vosotros resistís siempre al Espíritu Santo; como vuestros padres, así también vosotros.", "Esteban" }, { "Si crees de todo corazón, bien puedes.", "Felipe" }, { "A quienes entregué a Satanás para que aprendan a no blasfemar.", "Pablo" }, { "Tu pueblo será mi pueblo, y tu Dios mi Dios.", "Rut" }, { "Pues no es difícil para Jehová salvar con muchos o con pocos.", "Jonatán" }, { "Me habéis turbado con hacerme abominable a los moradores de esta tierra.", "Jacob" }, { "El viento sopla de donde quiere, y oyes su sonido.", "Jesus" }, { "María, no temas, porque has hallado gracia delante de Dios.", "Gabriel" }, { "Y mi espíritu se regocija en Dios mi Salvador.", "Maria" }, { "Ya que así habéis hecho, juro que me vengaré de vosotros, y después desistiré.", " Sanson" }, { "Si yo soy varón de Dios, descienda fuego del cielo, y consúmate con tus cincuenta.", "Elias" }, { "Yo soy el Alfa y la Omega, el principio y el fin, el primero y el último.", "Jesus" } }; //Palabras a adivinar Alfabeto = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ ".ToCharArray(); //PALABRA ALEATORIA= ADIVINAR Random random = new Random(); int IndicePalabraSeleccionada = random.Next(0, (Palabras.Length / 2)); PalabraSeleccionada = Palabras[IndicePalabraSeleccionada, 1].ToUpper().ToCharArray(); lblTexto.Text = Palabras[IndicePalabraSeleccionada, 0].ToUpper().ToString(); PalabrasAdivinadas = PalabraSeleccionada; // CICLO QUE CARGA EL ALFABETO EN UN FLOLAYOUT ---->Fichas de juego foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 65; btnLetra.Height = 45; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabras.Controls.Clear(); // ciclo ue agrega la palabra en un flolayout (palabra a adivinar) for (int IndiceValorLetra = 0; IndiceValorLetra < PalabraSeleccionada.Length; IndiceValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[IndiceValorLetra].ToString(); Letra.Text = "-"; Letra.Width = 46; Letra.Height = 80; Letra.ForeColor = Color.Green; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + IndiceValorLetra.ToString(); //Letra.BackgroundImage = ((System.Drawing.Image)(Properties.Resources.acertijo)); flPalabras.Controls.Add(Letra); } }
public void IniciarJuego(int Argumento) { flFichasDeJuego.Controls.Clear(); flFichasDeJuego.Enabled = true; pictureBox2.Visible = false; pictureBox3.Visible = false; pictureBox4.Visible = false; pictureBox5.Visible = false; pictureBox6.Visible = false; pictureBox7.Visible = false; lblMensaje.Visible = false; Oportunidades = 0; btnIniciarJuego.Image = Properties.Resources.jugando; Alfabeto = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ".ToCharArray(); Random random = new Random(); int IndicePalabraSeleccionada = random.Next(0, Palabras.Length); PalabraSeleccionada = Palabras[IndicePalabraSeleccionada].ToUpper().ToCharArray(); PalabrasAdivinadas = PalabraSeleccionada; //Cargando le alfabeto en el fl foreach (char LetraAlfabeto in Alfabeto) { Button btnLetra = new Button(); btnLetra.Tag = ""; btnLetra.Text = LetraAlfabeto.ToString(); btnLetra.Width = 60; btnLetra.Height = 40; btnLetra.Click += Compara; btnLetra.ForeColor = Color.White; btnLetra.Font = new Font(btnLetra.Font.Name, 15, FontStyle.Bold); btnLetra.BackgroundImageLayout = ImageLayout.Center; btnLetra.BackColor = Color.Black; btnLetra.Name = LetraAlfabeto.ToString(); flFichasDeJuego.Controls.Add(btnLetra); } flPalabra.Controls.Clear(); //Palabra elegida aletoriamente para adivinarla for (int IndiceValorLetra = 0; IndiceValorLetra < PalabraSeleccionada.Length; IndiceValorLetra++) { Button Letra = new Button(); Letra.Tag = PalabraSeleccionada[IndiceValorLetra].ToString(); Letra.Width = 46; Letra.Height = 70; Letra.Text = "-"; Letra.ForeColor = Color.Purple; Letra.Font = new Font(Letra.Font.Name, 32, FontStyle.Bold); Letra.BackgroundImageLayout = ImageLayout.Center; Letra.BackColor = Color.White; Letra.FlatStyle = System.Windows.Forms.FlatStyle.Flat; Letra.Name = "Adivinado" + IndiceValorLetra.ToString(); flPalabra.Controls.Add(Letra); } if (Argumento == 1) { Random r1 = new Random(); int aleatorio1 = r1.Next(0, PalabraSeleccionada.Length); int aleatorio2 = r1.Next(0, PalabraSeleccionada.Length); if (aleatorio1 == aleatorio2) { aleatorio2 = r1.Next(0, PalabraSeleccionada.Length); } for (int indiceRevisar = 0; indiceRevisar < PalabraSeleccionada.Length; indiceRevisar++) { if (PalabraSeleccionada[indiceRevisar].ToString() == PalabraSeleccionada[aleatorio1].ToString()) { Button tbx = this.Controls.Find("Adivinado" + indiceRevisar, true).FirstOrDefault() as Button; tbx.Text = PalabraSeleccionada[aleatorio1].ToString(); } if (PalabraSeleccionada[indiceRevisar].ToString() == PalabraSeleccionada[aleatorio2].ToString()) { Button tbx = this.Controls.Find("Adivinado" + indiceRevisar, true).FirstOrDefault() as Button; tbx.Text = PalabraSeleccionada[aleatorio2].ToString(); } } } else if (Argumento == 2) { Random r1 = new Random(); int aleatorio1 = r1.Next(0, PalabraSeleccionada.Length); for (int indiceRevisar = 0; indiceRevisar < PalabraSeleccionada.Length; indiceRevisar++) { if (PalabraSeleccionada[indiceRevisar].ToString() == PalabraSeleccionada[aleatorio1].ToString()) { Button tbx = this.Controls.Find("Adivinado" + indiceRevisar, true).FirstOrDefault() as Button; tbx.Text = PalabraSeleccionada[aleatorio1].ToString(); } } } }