/******************************************************************************** * * 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) { HD = new HardData(); HD.hard_summation_matrix = summation_matrix; HD.should_display_number = should_display_number; HD.initially_displayed = initially_displayed; HD.hard_right_edge = right_edge; HD.hard_bottom_edge = bottom_edge; HD.hard_custom_summation_matrix = custom_summation_matrix; HD.hard_custom_right_edge = custom_right_edge; HD.hard_custom_bottom_edge = custom_bottom_edge; Form1 form1 = new Form1(HD); Hard_Form Hard_Form = new Hard_Form(HD); form1.Show(); this.Hide(); Hard_Form.Close(); }
public Hard_Form(HardData HD) { this.HD = HD; summation_matrix = HD.hard_summation_matrix; should_display_number = HD.should_display_number; initially_displayed = HD.initially_displayed; right_edge = HD.hard_right_edge; bottom_edge = HD.hard_bottom_edge; custom_summation_matrix = HD.hard_custom_summation_matrix; original_summation_matrix = HD.hard_original_summation_matrix; custom_bottom_edge = HD.hard_custom_bottom_edge; custom_right_edge = HD.hard_custom_right_edge; Hard_White_Pen = new Pen(Color.White); InitializeComponent(); }
/******************************************************************************** * * Constructor: Form1 * * Arguments: HardData HD * * *******************************************************************************/ public Form1(HardData HD) { hardData1 = HD; myWhitePen = new Pen(Color.White); InitializeComponent(); }
/******************************************************************************** * * Method: InitializeHardData * * Arguments: * * Return Type: void * * Purpose: Initializes all hard files and reloads them. * * *******************************************************************************/ public void InitializeHardData() { if (hardData1 == null) { hardData1 = new HardData(); // HARD string hard_file = ""; Random random = new Random(); int hard_rand = random.Next(3); 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; } 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; } else { } 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++; } } }
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: Update_Hard_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_Hard_Form_Click(object sender, MouseEventArgs e) { Graphics g = Hard_Playing_Field.CreateGraphics(); int X = 0; int Y = 0; int width = Hard_Playing_Field.Width; int height = Hard_Playing_Field.Height; #region MouseLocator if (e.X < width / 8) { X = 0; } else if (e.X < ((2 * width) / 8)) { X = 1; } else if (e.X < ((3 * width) / 8)) { X = 2; } else if (e.X < ((4 * width) / 8)) { X = 3; } else if (e.X < ((5 * width) / 8)) { X = 4; } else if (e.X < ((6 * width) / 8)) { X = 5; } else if (e.X < ((7 * width) / 8)) { X = 6; } else { X = 7; } if (e.Y < height / 8) { Y = 0; } else if (e.Y < ((2 * height) / 8)) { Y = 1; } else if (e.Y < ((3 * height) / 8)) { Y = 2; } else if (e.Y < ((4 * height) / 8)) { Y = 3; } else if (e.Y < ((5 * height) / 8)) { Y = 4; } else if (e.Y < ((6 * height) / 8)) { Y = 5; } else if (e.Y < ((7 * height) / 8)) { Y = 6; } else { Y = 7; } #endregion if (HardTextBox.Text != "" && Regex.IsMatch(HardTextBox.Text, @"^\d+$") && HardTextBox.Text != "0") { string[] numbers_array = new string[100]; int number = Convert.ToInt32(HardTextBox.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, Hard_Black_Brush, (X * (width / 8)) + 3, (Y * (height / 8)) + 3); g.DrawString(numbers_array[i], input_Font_14, Hard_Black_Brush, (X * (width / 8)) + 3, (Y * (height / 8)) + 3); } if (X <= 6 && Y <= 6) { custom_summation_matrix[Y, X] = number; if (summation_matrix[Y, X] == number) { g.DrawString(number.ToString(), input_Font_14, Hard_Correct_Green_Brush, (X * (width / 8)) + 3, (Y * (height / 8)) + 3); 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(140); int time = 25 + completion; #endregion MessageBox.Show("You Won the Game! " + "\n Completion time: " + time + " seconds ", "SUCCESS", MessageBoxButtons.OK); HD.endTime = DateTime.Now.Millisecond; HD.solved = true; ClearCustomMatrix(); PullUpNewPuzzle(); int timeElapsed = (HD.endTime - HD.startTime) / 1000; if (HardData.bestTimeEver == 0 || HardData.bestTimeEver > timeElapsed) { HardData.bestTimeEver = timeElapsed; } HD = new HardData(); HD.startTime = DateTime.Now.Millisecond; } } else { g.DrawString(number.ToString(), input_Font_14, Hard_Incorrect_Red_Brush, (X * (width / 8)) + 3, (Y * (height / 8)) + 3); } LookAtSolution(); } } else { DisplayAlert("You entered too high of a value!", "ERROR"); } } } else { MessageBox.Show("Please make sure to enter integers only.", "ERROR", MessageBoxButtons.OK); } }