private void ExecuteOKCommand() { this.Riddle = BrickNode.TransformOriginal(this.Riddle); this.IsAnswerEnable = true; this.TimerState = CalculagraphState.Start; this.startTime = DateTime.Now; }
private void Initialize() { this.NumChangeCommand = new UserCommand(this.ExecuteNumChangeCommand); this.NewGameCommand = new UserCommand(this.ExecuteNewGameCommand); this.AnswerCommand = new UserCommand(this.ExecuteAnswerCommand); this.OKCommand = new UserCommand(this.ExecuteOKCommand); this.IsOKEnable = true; this.isAnswerEnable = false; this.startTime = DateTime.Now; this.endTime = DateTime.MinValue; if (AppSetting.Settings.HasCustomizeSudoku()) { this.Riddle = AppSetting.Settings.CustomizeSudoku; } else { this.Riddle = BrickNode.CreateNoneSudoku(); } this.LoadFinished = true; timer = new DispatcherTimer(); timer.Tick += (s, e) => { }; timer.Interval = TimeSpan.FromMilliseconds(NewGameSpan); }
private void StartNewGame() { //Create new and empty sudoku. this.Riddle = BrickNode.CreateNoneSudoku(); this.IsOKEnable = true; this.IsAnswerEnable = false; this.TimerState = CalculagraphState.Stop; this.TimerState = CalculagraphState.Reset; this.startTime = DateTime.Now; this.endTime = DateTime.MinValue; }
/// <summary> /// Get a random sudoku. The result would put in Riddle. /// </summary> /// <param name="originalCount"></param> private async Task <BrickNode[, ]> Random(int originalCount) { return(await Task.Factory.StartNew <BrickNode[, ]>(() => { BrickNode[,] sudoku = BrickNode.CreateGeneralSudoku(); if (this.Stop) { return BrickNode.CreateGeneralSudoku(); } for (int i = 0; i <= 8; i++) { for (int j = 0; j <= 8; j++) { sudoku[i, j].Number = 0; sudoku[i, j].Kind = BrickKind.General; } } Random random = new Random(1); for (int i = 0; i < originalCount; i++) { List <BrickNode> list = new List <BrickNode>(); int x = 0; int y = 0; while (list.Count == 0) { x = random.Next(8) * DateTime.Now.Millisecond % 9; y = random.Next(8) * DateTime.Now.Millisecond % 9; list = Sudoku.GetAvailableBrickNodes(sudoku, new MsPoint { X = x, Y = y }); } sudoku[x, y].Number = list[random.Next(9) * DateTime.Now.Millisecond % list.Count].Number; sudoku[x, y].Kind = BrickKind.Original; } this.Calculate(sudoku); if (!this.GotAnswer && !this.Stop) { return this.Riddle = this.RandomSudoku(originalCount).Result; } else { return this.Riddle = sudoku; } })); }
private void Traverse(BrickNode o, ISet <BrickNode> search, ISet <BrickNode> visited) { if (search.Contains(o) && visited.Contains(o) == false) { visited.Add(o); for (var i = 0; i < o.NeighboursArray.Length; i++) { var neighbour = o.NeighboursArray[i]; Traverse(neighbour, search, visited); } } }
private void Remove(BrickNode brickNode) { BrickToJoint.Remove(brickNode); Neighbours.Remove(brickNode); NeighboursArray = Neighbours.ToArray(); }
//shortcut to search neighbors private bool Contains(BrickNode brickNode) { return(Neighbours.Contains(brickNode)); }