Exemplo n.º 1
0
		/**********************************************************
		ANROP:      Anropas då Spela-knappen clickas.
		UPPGIFT:    Läser av radiobutton och skickar vidare vilken
					nivå som användaren har valt.
					Visar och döljer även spelplan och meny.
		***********************************************************/
		private void spela_Click(object sender, RoutedEventArgs e)
		{
            Timer();

			main = Application.Current.MainWindow as MainWindow;
            model = new SudokuModel();
            model.GetSetNewGame = true;
			main.spelplanComponent.lblAntalDrag.Content = "0";

            main.spelplanComponent.Visibility = Visibility.Visible;
			main.menuComponent.Visibility = Visibility.Collapsed;
                gbL.Visibility = Visibility.Collapsed;
                gbM.Visibility = Visibility.Collapsed;
                gbS.Visibility = Visibility.Collapsed;
                rbL.IsChecked = false;
                rbM.IsChecked = false;
                rbS.IsChecked = false;
                rbGrid.Margin = new Thickness(70, 0, 70, 160);
                btnSpela.IsEnabled = false;
           

			main.gridPrintComponent = model.PrintGrid(radioButtonChecked, main.gridPrintComponent);
			main.gridPrintComponent.Visibility = Visibility.Visible;
					
            
		}
Exemplo n.º 2
0
        private void Button_Click_DFS(object sender, RoutedEventArgs e)
        {
            int[,] board = MainWindow.initialization();
            if (MainWindow.checkTableRow(board) != null)
            {
                int[] i = MainWindow.checkTableRow(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + i[0].ToString() + i[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableColomn(board) != null)
            {
                int[] l = MainWindow.checkTableColomn(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }
            if (MainWindow.checkTableSquere(board) != null)
            {
                int[] l = MainWindow.checkTableSquere(board);
                foreach (TextBox tb in grid.Children)
                {
                    if (tb.Name == "textBox" + l[0].ToString() + l[1].ToString())
                    {
                        tb.Background = Brushes.PaleVioletRed;
                        return;
                    }
                }
            }

            // Pocetak algoritma
            DFS_Sudoku  dfs = new DFS_Sudoku();
            List <Node> steps_and_solution = dfs.solve_BFS(board);   // u matricu resenje smestamo rezultat

            /*  int[,] resenje = steps_and_solution[steps_and_solution.Count - 1].getState();
             * int r = 0;
             * int c = 0;
             *
             * foreach (TextBox tb in grid.Children)
             * {
             *    if (c == 9)
             *    {
             *        c = 0;
             *        r++;
             *        tb.Text = resenje[r, c].ToString();
             *        c++;
             *    }
             *    else
             *    {
             *        tb.Text = resenje[r, c].ToString();
             *        c++;
             *    }
             * }*/
            if (stop)
            {
                System.Threading.Thread thread = new Thread(new ParameterizedThreadStart(ThreadMethod));
                thread.Name = "UpdateThread";
                thread.Start(steps_and_solution);
            }
            return;
        }