private void Gr_MouseDown(object sender, MouseButtonEventArgs e) { e.Handled = true; for (int i = 0; i < crossLst.Count; i++) { if (crossLst[i].Name == (((sender as Grid).Children[0] as StackPanel).Children[1] as Label).Content.ToString()) { chCross = crossLst[i]; break; } } if (chCross.Name != "") { grCrossList.Visibility = Visibility.Collapsed; grCrossSlove.Visibility = Visibility.Visible; GenerateCrossword(); } }
private void btnApply_Click(object sender, RoutedEventArgs e) { List <Cross> lst = null; if (File.Exists("Cross.xml")) { XmlSerializer xmlFormat = new XmlSerializer(typeof(List <Cross>)); try { using (Stream fStream = File.OpenRead("Cross.xml")) { lst = (List <Cross>)xmlFormat.Deserialize(fStream); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { lst = new List <Cross>(); } Cross result = new Cross { Name = txtName.Text, CGroup = (CrossGroup)Enum.Parse(typeof(CrossGroup), cmbGroup.Text) }; int count; if (lst.Contains(result)) { MessageBox.Show("This name is already exists!", "Wrong data"); } else { for (int i = 0; i < _width; i++) { List <int> tmp = new List <int>(); count = 0; foreach (Label item in (grBody.Children[0] as Grid).Children) { if (Grid.GetColumn(item) == i) { if (item.Background != Brushes.Transparent) { count++; } else { if (count != 0) { tmp.Add(count); } count = 0; } } } if (count != 0) { tmp.Add(count); } result.hArr.Add(tmp); } for (int i = 0; i < _height; i++) { List <int> tmp = new List <int>(); count = 0; foreach (Label item in (grBody.Children[0] as Grid).Children) { if (Grid.GetRow(item) == i) { if (item.Background != Brushes.Transparent) { count++; } else { if (count != 0) { tmp.Add(count); } count = 0; } } } if (count != 0) { tmp.Add(count); } result.vArr.Add(tmp); } lst.Add(result); try { XmlSerializer xmlFormat = new XmlSerializer(typeof(List <Cross>)); using (Stream fStream = File.Create("Cross.xml")) { xmlFormat.Serialize(fStream, lst); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Close(); } }
bool CheckWin() { Cross result = new Cross(); int count; bool same = true; for (int i = 0; i < chCross.hArr.Count; i++) { List <int> tmp = new List <int>(); count = 0; foreach (Label item in (grCrossBody.Children[0] as Grid).Children) { if (Grid.GetColumn(item) == i) { if (item.Background != Brushes.Transparent) { count++; } else { if (count != 0) { tmp.Add(count); } count = 0; } } } if (count != 0) { tmp.Add(count); } result.hArr.Add(tmp); } for (int i = 0; i < chCross.vArr.Count; i++) { List <int> tmp = new List <int>(); count = 0; foreach (Label item in (grCrossBody.Children[0] as Grid).Children) { if (Grid.GetRow(item) == i) { if (item.Background != Brushes.Transparent) { count++; } else { if (count != 0) { tmp.Add(count); } count = 0; } } } if (count != 0) { tmp.Add(count); } result.vArr.Add(tmp); } try { for (int i = 0; i < chCross.hArr.Count; i++) { for (int j = 0; j < chCross.hArr[i].Count; j++) { if (chCross.hArr[i][j] != result.hArr[i][j]) { same = false; } } } } catch { } try { for (int i = 0; i < chCross.vArr.Count; i++) { for (int j = 0; j < chCross.vArr[i].Count; j++) { if (chCross.vArr[i][j] != result.vArr[i][j]) { same = false; } } } return(same); } catch { } return(false); }