using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Windows.Forms; namespace ustredniKolo2018 { public partial class Form1 : Form { //Variables that will be further used string input = string.Empty; Label[,] label = new Label[9,9]; bool canUndo = false; int lastTurn = 0; string lastTurnStr = ""; public Form1() { InitializeComponent(); } private void loadButton_Click(object sender, EventArgs e) { //File input throught textbox try { input = File.ReadAllText(dstTextbox.Text); } catch { MessageBox.Show("Invalid file path!"); } //Proccessing text input and generation of labels string[] inputLines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); for(int x = 0;x < 9;x++) { for (int y = 0; y < 9; y++) { char[] charInput = inputLines[y].ToCharArray(); label[x, y] = new Label(); if (charInput[x] != '.') { label[x, y].Text = charInput[x].ToString(); } else { label[x, y].Text = " "; } label[x, y].Location = new Point(50 + x * 51, 50 + y * 51); label[x, y].AutoSize = true; label[x, y].BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; label[x, y].Font = new Font(FontFamily.GenericSansSerif,35.0F, FontStyle.Bold); label[x, y].ForeColor = Color.Blue; label[x, y].Click += new EventHandler(labelSelect); this.Controls.Add(label[x, y]); } } } //Click handle - will select certain cell protected void labelSelect(object sender, EventArgs e) { foreach (Label lab in label) { lab.BackColor = Color.White; } Label lbl = sender as Label; lbl.BackColor = Color.Yellow; } //"Helpful" number input into selected cell private void numInput_Click(object sender, EventArgs e) { foreach (Label lab in label) { if (lab.Text == " " && lab.BackColor == Color.Yellow) { lab.BackColor = Color.White; lab.ForeColor = Color.Green; lab.Text = helpNumber.Value.ToString(); } else if (lab.ForeColor == Color.Green && lab.BackColor == Color.Yellow) { lab.BackColor = Color.White; lab.ForeColor = Color.Green; lab.Text = helpNumber.Value.ToString(); } else if (lab.ForeColor == Color.Black && lab.BackColor == Color.Yellow) { lab.BackColor = Color.White; lab.ForeColor = Color.Green; lab.Text = helpNumber.Value.ToString(); } else if (lab.BackColor == Color.Yellow) { lab.BackColor = Color.White; MessageBox.Show("That is one of the numbers that was given - you cannot change that!"); } } } //Inputting real deal numbers - error checking and solving is not implemented //Undo button variables input private void trueNumberInput_Click(object sender, EventArgs e) { foreach(Label lab in label) { if (lab.Text == " " && lab.BackColor == Color.Yellow) { lab.BackColor = SystemColors.Window; lab.ForeColor = Color.Black; try { lastTurn = Convert.ToInt32(lab.Text); } catch { lastTurnStr = lab.Text; } lab.Text = trueNumber.Value.ToString(); canUndo = true; } else if (lab.ForeColor == Color.Green && lab.BackColor == Color.Yellow) { lab.BackColor = SystemColors.Window; lab.ForeColor = Color.Black; try { lastTurn = Convert.ToInt32(lab.Text); } catch { lastTurnStr = lab.Text; } lab.Text = trueNumber.Value.ToString(); canUndo = true; } else if (lab.ForeColor == Color.Black && lab.BackColor == Color.Yellow) { lab.BackColor = SystemColors.Window; lab.ForeColor = Color.Black; try { lastTurn = Convert.ToInt32(lab.Text); } catch { lastTurnStr = lab.Text; } lab.Text = trueNumber.Value.ToString(); canUndo = true; } else if (lab.BackColor == Color.Yellow) { lab.BackColor = Color.White; MessageBox.Show("That is one the numbers that was given - you cannot change that!"); } } } //Single turn undo private void undoBtn_Click(object sender, EventArgs e) { if(canUndo) { foreach(Label lab in label) { if(lab.BackColor == SystemColors.Window) { if(lastTurnStr == " ") { lab.Text = " "; } else { lab.Text = lastTurn.ToString(); } canUndo = false; } } } else { MessageBox.Show("You can undo only once or after making a move!"); } } //Check for all nine private void nineChecker_Click(object sender, EventArgs e) { int one = 0; int two = 0; int three = 0; int four = 0; int five = 0; int six = 0; int seven = 0; int eight = 0; int nine = 0; foreach(Label l in label) { if (l.Text == " ") continue; if(Convert.ToInt32(l.Text) == 1) { one++; } else if (Convert.ToInt32(l.Text) == 2) { two++; } else if (Convert.ToInt32(l.Text) == 3) { three++; } else if (Convert.ToInt32(l.Text) == 4) { four++; } else if (Convert.ToInt32(l.Text) == 5) { five++; } else if (Convert.ToInt32(l.Text) == 6) { six++; } else if (Convert.ToInt32(l.Text) == 7) { seven++; } else if (Convert.ToInt32(l.Text) == 8) { eight++; } else if (Convert.ToInt32(l.Text) == 9) { nine++; } } if(one == 9) ones.Text = "1 : HOTOVO"; else ones.Text = "1 : NEHOTOVO"; if (two == 9) twos.Text = "2 : HOTOVO"; else twos.Text = "2 : NEHOTOVO"; if (three == 9) threes.Text = "3 : HOTOVO"; else threes.Text = "3 : NEHOTOVO"; if (four == 9) fours.Text = "4 : HOTOVO"; else fours.Text = "4 : NEHOTOVO"; if (five == 9) fives.Text = "5 : HOTOVO"; else fives.Text = "5 : NEHOTOVO"; if (six == 9) sixs.Text = "6 : HOTOVO"; else sixs.Text = "6 : NEHOTOVO"; if (seven == 9) sevens.Text = "7 : HOTOVO"; else sevens.Text = "7 : NEHOTOVO"; if (eight == 9) eights.Text = "8 : HOTOVO"; else eights.Text = "8 : NEHOTOVO"; if (nine == 9) nines.Text = "9 : HOTOVO"; else nines.Text = "9 : NEHOTOVO"; } } }