Advertisement
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
- {
- private void StopTextBoxClick(object sender, MouseButtonEventArgs e)
- {
- TextBox text = sender as TextBox;
- if (text != null && !text.IsKeyboardFocusWithin)
- {
- e.Handled = true;
- text.Focus();
- }
- }
- public MainWindow()
- {
- InitializeComponent();
- 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);
- 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 }};
- 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]);
- }
- }
- }
- private void TextChanged(object sender, TextChangedEventArgs e)
- {
- 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 }};
- // ТЫ СКАЗАЛ СДЕЛАТЬ ЭТО
- for (int i = 0; i < 9; i++)
- {
- for (int j = 0; j < 9; j++)
- {
- boxes[i, j].Background = Brushes.White;
- }
- }
- //
- try { int G = Convert.ToInt32((sender as TextBox).Text); }
- catch { (sender as TextBox).Text = ""; return; }
- if((sender as TextBox).Text == "0"){ (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++)
- {
- if (boxes[i, j] == (sender as TextBox))
- {
- ver = i;
- hor = j;
- }
- }
- }
- for (int i = 0; i < 9; i++)
- {
- if ((sender as TextBox).Text == "")
- {
- (sender as TextBox).Background = Brushes.White;
- break;
- }
- if ((sender as TextBox).Text == boxes[i , hor].Text)
- {
- if (boxes[i, hor] != (sender as TextBox))
- {
- boxes[i, hor].Background = Brushes.Red;
- (sender as TextBox).Background = Brushes.Red;
- }
- }
- if ((sender as TextBox).Text == boxes[ver, i].Text)
- {
- if(boxes[ver, i] != (sender as TextBox))
- {
- boxes[ver, i].Background = Brushes.Red;
- (sender as TextBox).Background = Brushes.Red;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement