/// <summary> /// Button load game /// Voor elke line(1t/m16) set picturebox.ImageLocation /// Laaste vijf lines voor speler + score + beurt /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button_LoadGame_Click(object sender, EventArgs e) { for (int i = 0; i < PictureBoxes.Count(); i++) { PictureBoxes[i] = null; } Stream myStream = null; var path = Path.Combine(Directory.GetCurrentDirectory(), "../../Resources/savefiles/"); OpenFileDialog openFile = new OpenFileDialog(); // Nieuwe fileDialog venster openFile.InitialDirectory = @"c:\\" + path; // Pad naar savFiles openFile.Filter = "Text files (*.txt)|*.txt"; // Filteren op .txt files openFile.FilterIndex = 2; // Twee index filters openFile.RestoreDirectory = true; if (openFile.ShowDialog() == DialogResult.OK) { try { if ((myStream = openFile.OpenFile()) != null) { using (StreamReader reader = new StreamReader(myStream)) { string line; string[] sline; string[] pline; line = reader.ReadLine(); // Lees de lines in bestand int c = 0; while (line != "asdfghjklqwertyuiop") // Voor elke Picturebox doe dan.. { sline = line.Split('|'); pline = sline[1].Split(','); pline[1] = pline[1].Replace("}", string.Empty); PictureBoxes[c].ImageLocation = sline[0]; // Zet line naar picturebox.imageLocation int x = Int32.Parse(pline[0].Split('=')[1]); int y = Int32.Parse(pline[1].Split('=')[1]); PictureBoxes[c].Tag = Image.FromFile(sline[0]); PictureBoxes[c].Image.Tag = sline[0]; PictureBoxes[c].Location = new Point(x, y); line = reader.ReadLine(); // Lees de lines in bestand c++; //showImages(); //<- is om te testen of loading picturebox images werkt } } } List <string> text = File.ReadLines(openFile.FileName).Reverse().Take(6).ToList(); naamP2 = text[3]; scoreP2 = Int32.Parse(text[2]); scoreP1 = Int32.Parse(text[4]); naamP1 = text[5]; MatrixSize = Int32.Parse(text[0]); } catch (Exception error) { MessageBox.Show("Error: Could not read file from disk. Original error: " + error.Message); } } }
private void ClickImage(object sender, EventArgs e) { if (!salliClick) { return; } var pic = (PictureBox)sender; if (arvaus == null) { arvaus = pic; pic.Image = (Image)pic.Tag; return; } label2.Text = Convert.ToString(Convert.ToInt32(label2.Text) - 5); pic.Image = (Image)pic.Tag; if (pic.Image == arvaus.Image && pic != arvaus) { pic.Visible = arvaus.Visible = false; { arvaus = pic; } label2.Text = Convert.ToString(Convert.ToInt32(label2.Text) + 15); HideImages(); } else { salliClick = false; clickAjastin.Start(); } arvaus = null; if (PictureBoxes.Any(p => p.Visible)) { return; } { StopGameTimer(); int loop = 0; DialogResult dialogResult = MessageBox.Show("Voitit! Haluatko jatkaa pelaamista?", "Voitit!", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { loop++; kierros++; } else if (dialogResult == DialogResult.No) { System.Windows.Forms.Application.ExitThread(); } label5.Text = kierros.ToString(); ResetImages(); label2.Text = "0"; } }
/// <summary> /// Als er een vrij slot is zoek dan nieuw image /// </summary> private PictureBox getFreeSlot() { int num; do { num = random.Next(0, PictureBoxes.Count()); } while (PictureBoxes[num].Tag != null); return(PictureBoxes[num]); }
private void ClickImage(object sender, EventArgs e) { if (!allowClick) { return; } guessCount++; var pic = (PictureBox)sender; DisplayGuessCount(); //Calls method to display guessCount DisplayAccuracy(); //Calls method to display the percent accuracy if (firstGuess == null) { firstGuess = pic; pic.Image = (Image)pic.Tag; return; } pic.Image = (Image)pic.Tag; if (pic.Image == firstGuess.Image && pic != firstGuess) { correctGuessCount++; //adds 1 to correct guess count label4.Text = correctGuessCount.ToString(); scoreLabel.Text = (correctGuessCount * 100).ToString(); //displays and calculates score pic.Visible = firstGuess.Visible = false; { firstGuess = pic; } HideImages(); } else { allowClick = false; clickTimer.Start(); } firstGuess = null; //Checks for any visible pictures, returns if yes, else stops timer & displays Win if (PictureBoxes.Any(p => p.Visible)) { return; } else { timer.Stop(); //Stops timer when all heross are correctly paired MessageBoxWinGame(); //Calls method when all heros are correctly paired } }
private void ClickImage(object sender, EventArgs e) { if (!allowClick) { return; } guessCount++; var pic = (PictureBox)sender; //label2.Text = guessCount.ToString(); DisplayGuessCount(); DisplayAccuracy(); if (firstGuess == null) { firstGuess = pic; pic.Image = (Image)pic.Tag; return; } pic.Image = (Image)pic.Tag; if (pic.Image == firstGuess.Image && pic != firstGuess) { correctGuessCount++; label4.Text = correctGuessCount.ToString(); scoreLabel.Text = (correctGuessCount * 100).ToString(); pic.Visible = firstGuess.Visible = false; { firstGuess = pic; } HideImages(); } else { allowClick = false; clickTimer.Start(); } firstGuess = null; if (PictureBoxes.Any(p => p.Visible)) { return; } else { timer.Stop(); MessageBoxWinGame(); } }
/// <summary> /// Click van image op picturebox zodat image wordt gedraaid /// Als geen paar hebt dan image weer verbergen /// Als ze gelijk zijn verwijder dan de image van het speelveld /// </summary> private void clickImage(object sender, EventArgs e) { if (!allowClick) { return; } var pic = (PictureBox)sender; if (firstGuess == null) { firstGuess = pic; pic.Image = (Image)pic.Tag; return; } pic.Image = (Image)pic.Tag; if (pic.Image == firstGuess.Image && pic != firstGuess) { pic.Visible = firstGuess.Visible = false; { firstGuess = pic; } hideImages(); } else { allowClick = false; clickTimer.Start(); } firstGuess = null; if (PictureBoxes.Any(p => p.Visible)) { return; } timer.Stop(); MessageBox.Show("Gefeliciteerd.", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"../../Resources/scoreboard.txt", true)) { file.WriteLine(naam + " : " + lblTime.Text + " time"); } resetImages(); }
/// <summary> /// Random image setten op vrij slot /// </summary> private void setRandomImages() { foreach (var image in Images) { getFreeSlot().Tag = image; getFreeSlot().Tag = image; for (int i = 0; i < 2; i++) { var box = PictureBoxes.FirstOrDefault(x => x.Tag == null); if (box == null) { Console.WriteLine("box is null"); } else { box.Image = image; } } } }
private void ClickImage(object sender, EventArgs e) { if (!allowClick) { return; } var pic = (PictureBox)sender; if (firstGuess == null) { firstGuess = pic; pic.Image = (Image)pic.Tag; return; } pic.Image = (Image)pic.Tag; if (pic.Image == firstGuess.Image && pic != firstGuess) { pic.Visible = firstGuess.Visible = false; { firstGuess = pic; } HideImages(); } else { allowClick = false; clickTimer.Start(); } firstGuess = null; if (PictureBoxes.Any(p => p.Visible)) { return; } MessageBox.Show("You won!", "Victory", MessageBoxButtons.OK); ResetImages(); allowClick = false; }
/// <summary> /// Click van image op picturebox zodat image wordt gedraaid /// Als geen paar hebt dan image weer verbergen /// Als ze gelijk zijn verwijder dan de image van het speelveld /// </summary> private void clickImage(object sender, EventArgs e) { if (!allowClick) { return; } var pic = (PictureBox)sender; if (firstGuess == null) { firstGuess = pic; pic.Image = (Image)pic.Tag; return; } pic.Image = (Image)pic.Tag; string picloc = pic.ImageLocation; string[] picloca = picloc.Split('/'); if (picloca[picloca.Length - 1][1] == 'o') { if (pic.Image == firstGuess.Image && pic != firstGuess) { pic.Visible = firstGuess.Visible = false; pic.Tag = null; firstGuess.Tag = null; { firstGuess = pic; } if (this.turn == 0) { scoreP1++; lblScoreP1.Text = naamP1 + ": " + scoreP1; } else { scoreP2++; lblScoreP2.Text = naamP2 + ": " + scoreP2; } hideImages(); } else { if (turn > 0) { turn--; } else { turn++; } switchTurns(); allowClick = false; clickTimer.Start(); } } else if (pic.ImageLocation == firstGuess.ImageLocation && pic != firstGuess) { pic.Visible = firstGuess.Visible = false; pic.Tag = null; firstGuess.Tag = null; { firstGuess = pic; } if (this.turn == 0) { scoreP1++; lblScoreP1.Text = naamP1 + ": " + scoreP1; } else { scoreP2++; lblScoreP2.Text = naamP2 + ": " + scoreP2; } hideImages(); } else { if (turn > 0) { turn--; } else { turn++; } switchTurns(); allowClick = false; clickTimer.Start(); } firstGuess = null; if (PictureBoxes.Any(p => p.Visible)) { return; } String winPlayer = ""; if (scoreP1 > scoreP2) { winPlayer = naamP1; WinningScore = scoreP1; } else { winPlayer = naamP2; WinningScore = scoreP2; } var path = Path.Combine(Directory.GetCurrentDirectory(), "../../Resources/VICTORY.wav"); System.Media.SoundPlayer sp = new System.Media.SoundPlayer(path); sp.Play(); MessageBox.Show("Gefeliciteerd " + winPlayer + " heeft gewonnen!", " ", MessageBoxButtons.OK, MessageBoxIcon.Information); using (StreamWriter file = new StreamWriter(Directory.GetCurrentDirectory() + "../../../Resources/scoreboardMulti.txt", true)) { file.WriteLine(winPlayer + ": " + WinningScore + " points"); } scoreGame scoreGame = new scoreGame(); scoreGame.Show(); }