/// <summary> /// 创建随机控件 /// </summary> /// <param name="Number"></param> /// <param name="color"></param> /// <param name="colorindex"></param> private bool CreateBoard() { int number = Create_Number(); Control_Grid control = new Control_Grid(number, number == 2 ? BackColors[0] : BackColors[1]); string name = "board" + NewName; control.Name = name; Point point = Create_Point(); if (point == new Point(0, 0)) { return(false); } Canvas.SetLeft(control, point.X); Canvas.SetTop(control, point.Y); canvas.Children.Add(control); point_Borders.Add(new Point_Border() { Name = name, Point = point, ColorIndex = number == 2 ? 0 : 1, Number = number }); NewName++; return(true); }
/// <summary> /// 创建新的控件 /// </summary> /// <param name="Number"></param> /// <param name="colorIndex"></param> /// <param name="point"></param> private void Create(int Number, int colorIndex, Point point) { Control_Grid control = new Control_Grid(Number, BackColors[colorIndex]); Canvas.SetLeft(control, point.X); Canvas.SetTop(control, point.Y); control.Name = "board" + NewName; canvas.Children.Add(control); point_Borders.Add(new Point_Border() { ColorIndex = colorIndex, Name = "board" + NewName, Number = Number, Point = point }); NewName++; }
/// <summary> /// 继续游戏 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click_1(object sender, RoutedEventArgs e) { try { string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//获取或设置包含该应用程序的目录的名称。 path += "File"; if (!Directory.Exists(path)) { panel.Visibility = Visibility.Collapsed; canvas.Visibility = Visibility.Visible; GameState = true; CreateBoard(); return; } path += "\\Note.txt"; StreamReader stream = new StreamReader(path); string note = stream.ReadToEnd(); stream.Close(); point_Borders = Json.JsonToObject <List <Point_Border> >(note, new List <Point_Border>()); foreach (var item in point_Borders) { Control_Grid control = new Control_Grid(item.Number, BackColors[item.ColorIndex]); Canvas.SetLeft(control, item.Point.X); Canvas.SetTop(control, item.Point.Y); control.Name = item.Name; canvas.Children.Add(control); } GameState = true; panel.Visibility = Visibility.Collapsed; canvas.Visibility = Visibility.Visible; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }