Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace WpfApplication6
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- Brush color;
- bool[,] coinc = new bool[9, 9];
- bool[,] start = new bool[9, 9];
- public TextBox[,] boxes()
- {
- TextBox[,] boxes = { { textBox1, textBox2, textBox3, textBox4, textBox5, textBox6, textBox7, textBox8, textBox9 } ,
- { textBox10, textBox11, textBox12, textBox13, textBox14, textBox15, textBox16, textBox17, textBox18 },
- { textBox19, textBox20, textBox21, textBox22, textBox23, textBox24, textBox25, textBox26, textBox27 },
- { textBox28, textBox29, textBox30, textBox31, textBox32, textBox33, textBox34, textBox35, textBox36 },
- { textBox37, textBox38, textBox39, textBox40, textBox41, textBox42, textBox43, textBox44, textBox45 },
- { textBox46, textBox47, textBox48, textBox49, textBox50, textBox51, textBox52, textBox53, textBox54 },
- { textBox55, textBox56, textBox57, textBox58, textBox59, textBox60, textBox61, textBox62, textBox63 },
- { textBox64, textBox65, textBox66, textBox67, textBox68, textBox69, textBox70, textBox71, textBox72 },
- { textBox73, textBox74, textBox75, textBox76, textBox77, textBox78, textBox79, textBox80, textBox81 }};
- return boxes;
- }
- public MainWindow()
- {
- InitializeComponent();
- color = boxes()[1,1].BorderBrush;
- string[] lines = System.IO.File.ReadAllLines(Environment.CurrentDirectory + @"\words.txt");
- char[,] table = new char[9, 9];
- Random rndA = new Random();
- int rnd = rndA.Next(0, lines.Length/10);
- boxes();
- for (int i = 0; i<9; i++)
- {
- char[] home = lines[rnd * 10 + i].ToCharArray();
- for (int j = 0; j<9; j++)
- {
- table[i, j] = home[j];
- if (Convert.ToString(home[j]) != " ")
- {
- boxes()[i, j].Text = Convert.ToString(home[j]);
- boxes()[i, j].IsReadOnly = true;
- start[i, j] = true;
- ColorChange(i, j, 3);
- }
- }
- }
- }
- public void kykarekalPetyx(TextBox sender, int hor, int ver)
- {
- if (sender.Text != "")
- {
- int[] COUB = { 0, 1, 2 };
- for (int i = 0; i < 9; i++)
- {
- if (sender.Text == boxes()[i, hor].Text)
- {
- if (boxes()[i, hor] != sender)
- {
- coinc[ver, hor] = true;
- coinc[i, hor] = true;
- ColorChange(ver, hor, 2);
- ColorChange(i, hor, 2);
- }
- }
- if (sender.Text == boxes()[ver, i].Text)
- {
- if (boxes()[ver, i] != sender)
- {
- ColorChange(ver, hor, 2);
- ColorChange(ver, i, 2);
- coinc[ver, hor] = true;
- coinc[ver, i] = true;
- }
- }
- }
- //
- double temp1 = ver / 3;
- double temp2 = hor / 3;
- int temp3 = COUB[(int)Math.Floor(temp1)] * 3;
- int temp4 = COUB[(int)Math.Floor(temp2)] * 3;
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (sender.Text == boxes()[temp3+i, temp4+j].Text)
- {
- if (boxes()[temp3 + i, temp4 + j] != sender)
- {
- ColorChange(temp3+i, temp4+j, 2);
- ColorChange(ver, hor, 2);
- coinc[temp3 + i, temp4 + j] = true;
- coinc[ver, hor] = true;
- }
- }
- }
- }
- }
- }
- public void ColorChange(int ver, int hor, int G)
- {
- if (G==1)
- {
- boxes()[ver, hor].BorderBrush = color;
- }
- else if(G==2)
- {
- boxes()[ver, hor].BorderBrush = Brushes.Red;
- }
- else
- {
- boxes()[ver, hor].Foreground = Brushes.DimGray;
- }
- }
- private void TextChanged(object sender, TextChangedEventArgs e)
- {
- if ((sender as TextBox).Text != "")
- {
- if ((Convert.ToChar((sender as TextBox).Text) < '1') || (Convert.ToChar((sender as TextBox).Text) > '9'))
- {
- (sender as TextBox).Text = "";
- return;
- }
- }
- int hor = 0;
- int ver = 0;
- for (int i = 0; i < 9; i++)
- {
- for (int j = 0; j < 9; j++)
- {
- ColorChange(i, j, 1);
- if (coinc[i, j])
- {
- kykarekalPetyx(boxes()[i, j], j, i);
- }
- if (boxes()[i, j] == (sender as TextBox))
- {
- ver = i;
- hor = j;
- }
- }
- }
- kykarekalPetyx((sender as TextBox), hor, ver);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment