using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Runtime.InteropServices; namespace Galgje { public partial class Form1 : Form { string guessTCor; string woordTCor; int randomTCor; int NrOfAttemptsTCor = 10; int characterCount; int wrongTCor; #region [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); #endregion public Form1() { InitializeComponent(); } private void btnSelectwordTCor_Click(object sender, EventArgs e) { SelectTCor(); } private void SelectTCor() { Random random = new Random(); randomTCor = random.Next(0, 9); if (randomTCor == 0) { woordTCor = "computer"; } if (randomTCor == 1) { woordTCor = "zomer"; } if (randomTCor == 2) { woordTCor = "strand"; } if (randomTCor == 3) { woordTCor = "katje"; } if (randomTCor == 4) { woordTCor = "huis"; } if (randomTCor == 5) { woordTCor = "sokken"; } if (randomTCor == 6) { woordTCor = "oranje"; } if (randomTCor == 7) { woordTCor = "vakantie"; } if (randomTCor == 8) { woordTCor = "muziek"; } if (randomTCor == 9) { woordTCor = "zwembad"; } tbCorrectwordTCor.Text = woordTCor; lblWordnumberTCor.Text = Convert.ToString(randomTCor + 1); } private void CountCharactersInWordAndQuestionMarks() { string m_charactersFound = ""; characterCount = 0; //deze textbox foreach (char m_char in tbCorrectwordTCor.Text) { m_charactersFound = m_charactersFound + "?"; //characterCount.ToString(); characterCount++; } //deze textbox tbGuessTCor.Text = m_charactersFound; } private void btnGoTCor_Click(object sender, EventArgs e) { try { CountCharactersInWordAndQuestionMarks(); NrOfAttemptsTCor = Convert.ToInt32(cbNuOfAttTCor.Text); lblLeftTCor.Text = Convert.ToString(NrOfAttemptsTCor); gbBeginTCor.Enabled = false; gbPlayTCor.Enabled = true; } catch { MessageBox.Show("Not all fields are filled in!"); } } // vul het getal in in ‘my guess’ //click ‘check It! //het gokje wordt gecontroleerd.. //de tekst het FOUT is, en: //‘oooh’ geluid //wrong en left (Ned:over) bijwerken //progressbar laat zien hoever to het eind.. //temperatuurmeter geeft hoe dichtbij.. warm… koud //de tekst als het GOED is, en: //‘applause’ geluid //geen kansen meer? ‘Boeeh’ en een Messagebox private void btnCheckitTCor_Click(object sender, EventArgs e) { guessTCor = tbLetterTCor.Text; string woordbcTCor = tbGuessTCor.Text; if (tbLetterTCor.Text.Trim() == "") { MessageBox.Show("Niet ingevuld"); } else { tbGuessTCor.Text = tbGuessTCor.Text = FindCharAndReturnCorrectedString(tbCorrectwordTCor.Text, guessTCor, tbGuessTCor.Text); if (woordbcTCor == tbGuessTCor.Text) { mciSendString("close Mediafile", null, 0, IntPtr.Zero); string m_location; m_location = Application.StartupPath; m_location = m_location + "\\..\\..\\snd\\boo.mp3"; mciSendString("open \"" + m_location + "\" type mpegvideo alias Mediafile", null, 0, IntPtr.Zero); mciSendString("play Mediafile", null, 0, IntPtr.Zero); NrOfAttemptsTCor--; wrongTCor++; if (NrOfAttemptsTCor == 0) { mciSendString("close Mediafile", null, 0, IntPtr.Zero); string m_location2; m_location2 = Application.StartupPath; m_location2 = m_location + "\\..\\..\\snd\\aww.mp3"; mciSendString("open \"" + m_location + "\" type mpegvideo alias Mediafile", null, 0, IntPtr.Zero); mciSendString("play Mediafile", null, 0, IntPtr.Zero); this.Controls.Clear(); MessageBox.Show("You lost, but look look at this panda!! :-)"); } } else { } if (tbGuessTCor.Text == tbCorrectwordTCor.Text) { string m_location; m_location = Application.StartupPath; m_location = m_location + "\\..\\..\\snd\\applause.mp3"; mciSendString("open \"" + m_location + "\" type mpegvideo alias Mediafile", null, 0, IntPtr.Zero); mciSendString("play Mediafile", null, 0, IntPtr.Zero); this.Controls.Clear(); this.InitializeComponent(); MessageBox.Show("Gefeliciteerd! U heeft gewonnen!"); } lblWrongTCor.Text = Convert.ToString(wrongTCor); lblLeftTCor.Text = Convert.ToString(NrOfAttemptsTCor); pbAttemptsTCor.Value = NrOfAttemptsTCor; } } //About private void btnAboutTCor_Click(object sender, EventArgs e) { MessageBox.Show("Gemaakt door:" + "\t" + "Tim Cortenbach" + "\n" + "Applicatie:" + "\t" + "Galgje" + "\n" + "Version:" + "\t" + "\t" + "Panda 1.4" + "\n" + "Datum:" + "\t" + "\t" + " 27Feb2014" + "\n" + "School:" + "\t" + "\t" + " ROC Ter AA" + "\n" + "Thanks to:" + "\t" + "\t" + " Niels van den Boogaart", "About"); } //Locate private void btnLocateTCor_Click(object sender, EventArgs e) { MessageBox.Show(Path.GetDirectoryName(Application.ExecutablePath), "Locatie Raad Het Getal"); } //Release private void btnReleaseTCor_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("notepad.exe", "log.rtf"); } private void chbCheatTCor_Checked(object sender, EventArgs e) { if (chbCheatTCor.Checked == true) { gbCheatTCor.Visible = true; } else { gbCheatTCor.Visible = false; } } private string FindCharAndReturnCorrectedString(string a_unknownWord, string a_findCharacter, string a_lettersKnownSofar) { StringBuilder m_lettersKnownSofar = new StringBuilder(a_lettersKnownSofar); int m_foundCharIndex; //niet nodig als lengte textbox op 1 is ingesteld, whitebox test in beoordeling if (a_findCharacter.Length > 1) { MessageBox.Show("One letter allowed! Only the first letter was used.", "Error"); } try { for (m_foundCharIndex = 0; m_foundCharIndex < a_unknownWord.Length; m_foundCharIndex++) { if (a_unknownWord[m_foundCharIndex] == a_findCharacter[0]) { m_lettersKnownSofar[m_foundCharIndex] = a_findCharacter[0]; } } } catch { MessageBox.Show("Find character field is empty..", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } return m_lettersKnownSofar.ToString(); } private void cbNuOfAttTCor_SelectedIndexChanged(object sender, EventArgs e) { } private void tbGuessTCor_TextChanged(object sender, EventArgs e) { } private void tbLetterTCor_TextChanged(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { gbPlayTCor.Enabled = false; } } }