Exemplo n.º 1
0
        private void solveButton_Click(object sender, RoutedEventArgs e)
        {
            // History leeren
            this.listHistoryItems.Clear();

            MainViewModel cube = this.LayoutRoot.DataContext as MainViewModel;

            RubiksCube.Controller.CubeSolver solver = new RubiksCube.Controller.CubeSolver(cube);

            //// solve the cube if solvable
            //if(solver.Cube.isSolvable)
            //{
            try
            {
                this.lblError.Content = String.Empty;
                solver.solve();


                this.LayoutRoot.DataContext = null;
                this.LayoutRoot.DataContext = solver.Cube as MainViewModel;

                // Upcasting Cube
                foreach (RubiksCube.Model.HistoryItem item in solver.Cube.History)
                {
                    item.Cube = new MainViewModel(item.Cube);
                }

                this.actualHistoryItem = 0;
                this.listHistoryItems  = solver.Cube.History;

                setButtons();

                this.HistoryControl.ItemsSource = this.listHistoryItems;
                if (this.listHistoryItems.Count > 0)
                {
                    this.GridOneByOne.DataContext = this.listHistoryItems[actualHistoryItem];
                }
            }
            catch (RubiksCube.Controller.NotSolvableException)
            {
                // current cube is not solvable
                this.listHistoryItems.Clear();
                this.GridOneByOne.DataContext = null;
                this.btnNext.IsEnabled        = false;
                this.btnPrevious.IsEnabled    = false;
                this.lblError.Content         = "This cube is not solvable!";
            }
            //}
            //else
            //{
            //    // current cube is not solvable
            //    this.listHistoryItems.Clear();
            //    this.GridOneByOne.DataContext = null;
            //    this.btnNext.IsEnabled = false;
            //    this.btnPrevious.IsEnabled = false;
            //    this.lblError.Content = "This cube is not solvable!";
            //}
        }
Exemplo n.º 2
0
        private void solveButton_Click(object sender, RoutedEventArgs e)
        {
            // History leeren
            this.listHistoryItems.Clear();

            MainViewModel cube = this.LayoutRoot.DataContext as MainViewModel;
            RubiksCube.Controller.CubeSolver solver = new RubiksCube.Controller.CubeSolver(cube);

            //// solve the cube if solvable
            //if(solver.Cube.isSolvable)
            //{
            try
            {
                this.lblError.Content = String.Empty;
                solver.solve();

                this.LayoutRoot.DataContext = null;
                this.LayoutRoot.DataContext = solver.Cube as MainViewModel;

                // Upcasting Cube
                foreach (RubiksCube.Model.HistoryItem item in solver.Cube.History)
                {
                    item.Cube = new MainViewModel(item.Cube);
                }

                this.actualHistoryItem = 0;
                this.listHistoryItems = solver.Cube.History;

                setButtons();

                this.HistoryControl.ItemsSource = this.listHistoryItems;
                if (this.listHistoryItems.Count > 0)
                {
                    this.GridOneByOne.DataContext = this.listHistoryItems[actualHistoryItem];
                }
            }
            catch (RubiksCube.Controller.NotSolvableException)
            {
                // current cube is not solvable
                this.listHistoryItems.Clear();
                this.GridOneByOne.DataContext = null;
                this.btnNext.IsEnabled = false;
                this.btnPrevious.IsEnabled = false;
                this.lblError.Content = "This cube is not solvable!";
            }
            //}
            //else
            //{
            //    // current cube is not solvable
            //    this.listHistoryItems.Clear();
            //    this.GridOneByOne.DataContext = null;
            //    this.btnNext.IsEnabled = false;
            //    this.btnPrevious.IsEnabled = false;
            //    this.lblError.Content = "This cube is not solvable!";
            //}
        }