private void CheckForWinner() //Revisa que los colores de las imagenes y el fondo NO sean iguales { // Go through all of the labels in the TableLayoutPanel, // checking each one to see if its icon is matched foreach (Control control in tableLayoutPanel1erGrado.Controls) { Label iconLabel = control as Label; if (iconLabel != null) { //Para que solo se gane cuando el tablero esté vacío if (iconLabel.ForeColor != iconLabel.BackColor) { return; } } } // If the loop didn’t return, it didn't find // any unmatched icons // That means the user won. Show a message and close the form sonidos.sonidoTerminarBien(); MyMsgBox.Show("YOU MATCHED ALL THE WORDS!", ":)", "OK"); InitializeComponent(); m1grado = new Menu1erGrado(); m1grado.Show(); this.Hide(); return; }
//Que esto ocurra siempre que el juego inicie y cuando se confirme que una respuesta es correcta private void asignarPregYResp() { sameBackColor(); if (i + 1 < questions.Length) { i++; } else { if (score > 6) { sonidos.sonidoTerminarBien(); } else { sonidos.sonidoTerminar(); } MyMsgBox.Show("FINISH!\nFinal score: " + +score + " / " + questions.Length.ToString(), "", "OK"); InitializeComponent(); m1er = new Menu1erGrado(); m1er.Show(); this.Hide(); return; } KeyValuePair <string[], int> pair; labelQuant.Text = (i + 1).ToString() + " / " + questions.Length.ToString() + " Score: " + score + " / " + questions.Length.ToString(); labelQuestion.Text = questions[i]; Image im = imageList1.Images[i]; //La imagen de la lista de imagenes labelQuestion.Image = im; int cant; Random rand = new Random(); numbers = new int[4] { 0, 1, 2, 3 }; pair = allAnswers.ElementAt(i); labelAnswer1.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer2.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer3.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer4.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; //numbers = numbers.Where(w => w != numbers[cant]).ToArray(); /* * Image ima = Image.FromFile("image.png"); // read in image * ilabel.Size = new Size(i.Width, i.Height); //set label to correct size * ilabel.Image = i; // put image on label * this.Controls.Add(ilabel); // add label to container (a form, for instance) */ labelNext.Visible = false; }
//Que esto ocurra siempre que el juego inicie y cuando se confirme que una respuesta es correcta private void asignarPregYResp() { sameBackColor(); if (i + 1 < questions.Length) { i++; } else { if (score > 6) { sonidos.sonidoTerminarBien(); } else { sonidos.sonidoTerminar(); } MyMsgBox.Show("FINISH!\nFinal score: " + +score + " / " + questions.Length.ToString(), "", "OK"); InitializeComponent(); m2do = new Menu2doGrado(); m2do.Show(); this.Hide(); return; } KeyValuePair <string[], int> pair; labelQuant.Text = (i + 1).ToString() + " / " + questions.Length.ToString() + " Score: " + score + " / " + questions.Length.ToString(); labelQuestion.Text = questions[i]; Image im = imageList1.Images[i]; //La imagen de la lista de imagenes labelQuestion.Image = im; int cant; Random rand = new Random(); numbers = new int[4] { 0, 1, 2, 3 }; pair = allAnswers.ElementAt(i); labelAnswer1.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer2.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer3.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelAnswer4.Text = pair.Key[numbers[cant = rand.Next(0, numbers.Length)]]; //numbers = numbers.Where(w => w != numbers[cant]).ToArray(); labelNext.Visible = false; }
//Se actualiza el numero de palabras completadas, el numero de errores, //los colores de las letras y se verifica si se completó la palabra private void updateInfo(String letter) { //Si es la letra que sigue para completar (opcion correcta) if (letter == System.Convert.ToString(word[numLetra])) { //Sonido de exito (quitarlo?) //sonidos.sonidoGanarSebastian(); //Sonido de la letra synthesizer.Speak(letter); //Pasa a la siguiente letra en la lista numLetra++; int wordSize = word.Length; //Si ya se completó la palabra if (numLetra == wordSize) { score++; synthesizer.Speak(word); //System.Threading.Thread.Sleep(500); //Si se completaron todas las palabras, popup de victoria y de vuelta al menu principal if (score == 5) { labelInfo.Text = score + "/5 words completed Mistakes: " + mistakes; sonidos.sonidoTerminarBien(); MyMsgBox.Show("CONGRATULATIONS!\nYou completed all the words!", ":)", "OK"); InitializeComponent(); m1er = new Menu1erGrado(); m1er.Show(); this.Hide(); return; } setValues(); } else { Control label; //Cambiar color de la letra recien completada y de la que sigue si faltan for (int i = 0; i < wordSize; i++) { label = tableLayoutPanelLetters.GetControlFromPosition(i, 0); if (label is Label) { //Si es la letra siguiente a completar, color azul if (i == numLetra) { label.Text = System.Convert.ToString(word[i]); label.ForeColor = System.Drawing.Color.Blue; } //Si la letra ya fue completada, color verde else if (i < numLetra) { label.Text = System.Convert.ToString(word[i]); label.ForeColor = System.Drawing.Color.Green; } //Si la letra falta de completar pero no es la siguiente, negra //(CREO QUE ESTA NO SE OCUPA) else { label.Text = System.Convert.ToString(word[i]); label.ForeColor = System.Drawing.Color.Black; } } } changeOptionsInButtons(); } } else { //Sonido de fracaso sonidos.sonidoPerderSebastian(); mistakes++; } //El juego se gana completando 5 palabras labelInfo.Text = score + "/5 words completed Mistakes: " + mistakes; }