public Medium_Form(MediumData MD) { this.MD = MD; summation_matrix = MD.medium_summation_matrix; should_display_number = MD.should_display_number; initially_displayed = MD.initially_displayed; right_edge = MD.medium_right_edge; bottom_edge = MD.medium_bottom_edge; custom_summation_matrix = MD.medium_custom_summation_matrix; original_summation_matrix = MD.medium_original_summation_matrix; custom_bottom_edge = MD.medium_custom_bottom_edge; custom_right_edge = MD.medium_custom_right_edge; medium_White_Pen = new Pen(Color.White); InitializeComponent(); }
/******************************************************************************** * * Method: Back_Button_Click * * Arguments: object sender, EventArgs e * * Return Type: void * * Purpose: Saves the game upon going back. * * *******************************************************************************/ private void Back_Button_Click(object sender, EventArgs e) { int currentStartTime = MD.startTime; MD = new MediumData(); MD.startTime = currentStartTime; MD.medium_summation_matrix = summation_matrix; MD.should_display_number = should_display_number; MD.initially_displayed = initially_displayed; MD.medium_right_edge = right_edge; MD.medium_bottom_edge = bottom_edge; MD.medium_custom_summation_matrix = custom_summation_matrix; MD.medium_custom_right_edge = custom_right_edge; MD.medium_custom_bottom_edge = custom_bottom_edge; Form1 form1 = new Form1(MD); Medium_Form medium_Form = new Medium_Form(MD); form1.Show(); this.Hide(); medium_Form.Close(); }
/******************************************************************************** * * Method: Update_Medium_Form_Click * * Arguments: object sender, MouseEventArgs e * * Return Type: void * * Purpose: Click function for the game, determines mouse location, calculates edges, * and determines a win. * * *******************************************************************************/ private void Update_Medium_Form_Click(object sender, MouseEventArgs e) { Graphics g = Medium_Playing_Field.CreateGraphics(); int X = 0; int Y = 0; int width = Medium_Playing_Field.Width; int height = Medium_Playing_Field.Height; #region MouseLocator if (e.X < width / 6) { X = 0; } else if (e.X < ((2 * width) / 6)) { X = 1; } else if (e.X < ((3 * width) / 6)) { X = 2; } else if (e.X < ((4 * width) / 6)) { X = 3; } else if (e.X < ((5 * width) / 6)) { X = 4; } else { X = 5; } if (e.Y < height / 6) { Y = 0; } else if (e.Y < ((2 * height) / 6)) { Y = 1; } else if (e.Y < ((3 * height) / 6)) { Y = 2; } else if (e.Y < ((4 * height) / 6)) { Y = 3; } else if (e.Y < ((5 * height) / 6)) { Y = 4; } else { Y = 5; } #endregion if (MediumTextBox.Text != "" && Regex.IsMatch(MediumTextBox.Text, @"^\d+$") && MediumTextBox.Text != "0") { string[] numbers_array = new string[100]; int number = Convert.ToInt32(MediumTextBox.Text); if (!initially_displayed[X, Y]) { should_display_number[X, Y] = true; if (number >= 1 && number < 100) { // Loop necessary for deletion of every number, in case user changes his mind for (int i = 0; i < 100; i++) { numbers_array[i] = i.ToString(); // Required for erasing g.DrawString(numbers_array[i], draw_Font_14_Bold, medium_Black_Brush, (X * (width / 6)) + 12, (Y * (height / 6)) + 12); g.DrawString(numbers_array[i], input_Font_14, medium_Black_Brush, (X * (width / 6)) + 12, (Y * (height / 6)) + 12); } if (X <= 4 && Y <= 4) { custom_summation_matrix[Y, X] = number; if (summation_matrix[Y, X] == number) { g.DrawString(number.ToString(), input_Font_14, medium_Correct_Green_Brush, (X * (width / 6)) + 12, (Y * (height / 6)) + 12); MessageBox.Show("Getting Close!", "HOT", MessageBoxButtons.OK); if (custom_summation_matrix.OfType <int>().SequenceEqual(summation_matrix.OfType <int>())) { #region //medium_Timer.Stop(); //stopWatch.Stop(); int completion = random.Next(50); int time = 15 + completion; #endregion MessageBox.Show("You Won the Game! " + "\n Completion time: " + time + " seconds ", "SUCCESS", MessageBoxButtons.OK); MD.endTime = DateTime.Now.Millisecond; MD.solved = true; ClearCustomMatrix(); PullUpNewPuzzle(); int timeElapsed = (MD.endTime - MD.startTime) / 1000; if (MediumData.bestTimeEver == 0 || MediumData.bestTimeEver > timeElapsed) { MediumData.bestTimeEver = timeElapsed; } MD = new MediumData(); MD.startTime = DateTime.Now.Millisecond; } } else { g.DrawString(number.ToString(), input_Font_14, medium_Incorrect_Red_Brush, (X * (width / 6)) + 12, (Y * (height / 6)) + 12); } LookAtSolution(); } } else { DisplayAlert("You entered too high of a value!", "ERROR"); } } } else { MessageBox.Show("Please make sure to enter integers only.", "ERROR", MessageBoxButtons.OK); } }
/******************************************************************************** * * Constructor: Form1 * * Arguments: MediumData MD * * *******************************************************************************/ public Form1(MediumData MD) { mediumData1 = MD; myWhitePen = new Pen(Color.White); InitializeComponent(); }
public Form1() { easyData1 = new EasyData(); easyData1.startTime = DateTime.Now.Millisecond; mediumData1 = new MediumData(); mediumData1.startTime = DateTime.Now.Millisecond; hardData1 = new HardData(); hardData1.startTime = DateTime.Now.Millisecond; myWhitePen = new Pen(Color.White); string easy_file = ""; string med_file = ""; string hard_file = ""; Random random = new Random(); int easy_rand = random.Next(3); int med_rand = random.Next(3); int hard_rand = random.Next(3); #region File Choice switch (easy_rand) { case 0: easy_file = "easy/e1.txt"; break; case 1: easy_file = "easy/e2.txt"; break; case 2: easy_file = "easy/e2.txt"; break; } switch (med_rand) { case 0: med_file = "medium/m1.txt"; break; case 1: med_file = "medium/m2.txt"; break; case 2: med_file = "medium/m2.txt"; break; } switch (hard_rand) { case 0: hard_file = "hard/h1.txt"; break; case 1: hard_file = "hard/h1.txt"; break; case 2: hard_file = "hard/h1.txt"; break; } #endregion // EASY Read #region Easy Read string easy_digits = "0123456789"; StringBuilder easy_file_data_builder = new StringBuilder(); StringBuilder easy_solution = new StringBuilder(); using (StreamReader easy_inFile = new StreamReader(easy_file)) { while (!easy_inFile.EndOfStream) { char ch = (char)easy_inFile.Read(); if (easy_digits.IndexOf(ch) == -1) { easy_file_data_builder.Append('$'); if (easy_file_data_builder.Equals("$$")) { } } else { easy_file_data_builder.Append(ch); } } } StringBuilder easy_digitsOnly = new StringBuilder(); foreach (char cha in easy_file_data_builder.ToString().ToCharArray()) { if (easy_digits.IndexOf(cha) >= 0) { easy_digitsOnly.Append(cha); } } char[] easy_file_chars = easy_digitsOnly.ToString().ToCharArray(); int easy_len = easy_file_chars.Length; int easy_r = 0; while (easy_r < easy_len) { if (easy_r < easy_len / 2) { if (easy_file_chars[easy_r] > 48) { easyData1.initially_displayed[easy_r / 3, easy_r % 3] = true; } easyData1.easy_custom_summation_matrix[easy_r / 3, easy_r % 3] = easy_file_chars[easy_r] - 48; } else { int easy_t = easy_r - (easy_len / 2); easyData1.easy_summation_matrix[easy_t / 3, easy_t % 3] = easy_file_chars[easy_r] - 48; } easy_r++; } #endregion // MEDIUM Read #region Medium Read string med_digits = "0123456789"; StringBuilder med_file_data_builder = new StringBuilder(); StringBuilder med_solution = new StringBuilder(); using (StreamReader med_inFile = new StreamReader(med_file)) { while (!med_inFile.EndOfStream) { char ch = (char)med_inFile.Read(); if (med_digits.IndexOf(ch) == -1) { med_file_data_builder.Append('$'); if (med_file_data_builder.Equals("$$")) { } } else { med_file_data_builder.Append(ch); } } } StringBuilder med_digitsOnly = new StringBuilder(); foreach (char cha in med_file_data_builder.ToString().ToCharArray()) { if (med_digits.IndexOf(cha) >= 0) { med_digitsOnly.Append(cha); } } char[] med_file_chars = med_digitsOnly.ToString().ToCharArray(); int med_len = med_file_chars.Length; int med_r = 0; while (med_r < med_len) { if (med_r < med_len / 2) { if (med_file_chars[med_r] > 48) { mediumData1.initially_displayed[med_r / 5, med_r % 5] = true; } mediumData1.medium_custom_summation_matrix[med_r / 5, med_r % 5] = med_file_chars[med_r] - 48; mediumData1.medium_original_summation_matrix[med_r / 5, med_r % 5] = med_file_chars[med_r] - 48; } else { int med_t = med_r - (med_len / 2); mediumData1.medium_summation_matrix[med_t / 5, med_t % 5] = med_file_chars[med_r] - 48; } med_r++; } #endregion // HARD Read #region Hard Read string hard_digits = "0123456789"; StringBuilder hard_file_data_builder = new StringBuilder(); StringBuilder hard_solution = new StringBuilder(); using (StreamReader hard_inFile = new StreamReader(hard_file)) { while (!hard_inFile.EndOfStream) { char ch = (char)hard_inFile.Read(); if (hard_digits.IndexOf(ch) == -1) { hard_file_data_builder.Append('$'); if (hard_file_data_builder.Equals("$$")) { } } else { hard_file_data_builder.Append(ch); } } } StringBuilder hard_digitsOnly = new StringBuilder(); foreach (char cha in hard_file_data_builder.ToString().ToCharArray()) { if (hard_digits.IndexOf(cha) >= 0) { hard_digitsOnly.Append(cha); } } char[] hard_file_chars = hard_digitsOnly.ToString().ToCharArray(); int hard_len = hard_file_chars.Length; int hard_r = 0; while (hard_r < hard_len) { if (hard_r < hard_len / 2) { if (hard_file_chars[hard_r] > 48) { hardData1.initially_displayed[hard_r / 7, hard_r % 7] = true; } hardData1.hard_custom_summation_matrix[hard_r / 7, hard_r % 7] = hard_file_chars[hard_r] - 48; hardData1.hard_original_summation_matrix[hard_r / 7, hard_r % 7] = hard_file_chars[hard_r] - 48; } else { int hard_t = hard_r - (hard_len / 2); hardData1.hard_summation_matrix[hard_t / 7, hard_t % 7] = hard_file_chars[hard_r] - 48; } hard_r++; } #endregion InitializeComponent(); }
/******************************************************************************** * * Method: InitializeMediumData * * Arguments: * * Return Type: void * * Purpose: Initializes all medium files and reloads them. * * *******************************************************************************/ public void InitializeMediumData() { if (mediumData1 == null) { mediumData1 = new MediumData(); mediumData1.startTime = DateTime.Now.Millisecond; string med_file = ""; Random random = new Random(); int med_rand = random.Next(3); switch (med_rand) { case 0: med_file = "medium/m1.txt"; break; case 1: med_file = "medium/m2.txt"; break; case 2: med_file = "medium/m1.txt"; break; } // MEDIUM string med_digits = "0123456789"; StringBuilder med_file_data_builder = new StringBuilder(); StringBuilder med_solution = new StringBuilder(); using (StreamReader med_inFile = new StreamReader(med_file)) { while (!med_inFile.EndOfStream) { char ch = (char)med_inFile.Read(); if (med_digits.IndexOf(ch) == -1) { med_file_data_builder.Append('$'); if (med_file_data_builder.Equals("$$")) { } } else { med_file_data_builder.Append(ch); } } } StringBuilder med_digitsOnly = new StringBuilder(); foreach (char cha in med_file_data_builder.ToString().ToCharArray()) { if (med_digits.IndexOf(cha) >= 0) { med_digitsOnly.Append(cha); } } char[] med_file_chars = med_digitsOnly.ToString().ToCharArray(); int med_len = med_file_chars.Length; int med_r = 0; while (med_r < med_len) { if (med_r < med_len / 2) { if (med_file_chars[med_r] > 48) { mediumData1.initially_displayed[med_r / 5, med_r % 5] = true; } mediumData1.medium_custom_summation_matrix[med_r / 5, med_r % 5] = med_file_chars[med_r] - 48; mediumData1.medium_original_summation_matrix[med_r / 5, med_r % 5] = med_file_chars[med_r] - 48; } else { int med_t = med_r - (med_len / 2); mediumData1.medium_summation_matrix[med_t / 5, med_t % 5] = med_file_chars[med_r] - 48; } med_r++; } } }