Example #1
0
        private void OnPuzzleButtonClick(object sender, RoutedEventArgs e)
        {
            //*** ONCE A TILE HAS BEEN CLICKED MOVE IT IF IT IS A VALID MOVE ***
            if (_isProcessingButton == true)
            {
                //  this.IsEnabled = false;
                GazeAgumentedButton b = e.Source as GazeAgumentedButton;  //identify the button that has been clicked
                if (b != null)
                {
                    //Get the row and column of the button that has been cliced
                    int row = (int)b.GetValue(Grid.RowProperty);
                    int col = (int)b.GetValue(Grid.ColumnProperty);

                    //check to see if which direct the button should be moved
                    MoveStatus moveStatus = _puzzleLogic.GetMoveStatus(row, col);

                    if (moveStatus != MoveStatus.BadMove)
                    {
                        //as long as the move is valid, animate the movement by calling Animatepiece
                        AnimatePiece(b, row, col, moveStatus);
                    }
                    else
                    {
                        //Bad move, so allow a new button to be selected
                        _isProcessingButton = false;
                        // this.IsEnabled = true;
                    } //if-else
                }     //if
            }         //_isprocessingButton
        }
Example #2
0
 private void Window_MouseDown(object sender, MouseButtonEventArgs e)
 {
     //click the selected button
     if (GazeAugmentedPuzzleGrid.IsProcessingButton == false)
     {
         GazeAgumentedButton.ButtonSelected();
     }
 }
Example #3
0
        private void MovePiece(GazeAgumentedButton b, int row, int col)
        {         //*** MOVE THE TILE, ASSUMING THE MOVE IS VALID***
            //Identify the cell to move

            PuzzleCell newPosition = _puzzleLogic.MovePiece(row, col);

            try
            {
                //change the position of the tile in the grid
                b.SetValue(Grid.ColumnProperty, newPosition.Col);
                b.SetValue(Grid.RowProperty, newPosition.Row);

                //increment moves by 1
                _moves++;

                //Once the piece has been moved, then allow the next piece to be moved
                _isProcessingButton = false;
                //this.IsEnabled = true;//enable the grid
            }
            catch (Exception ex)
            {
                MessageBox.Show("Movement error !!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #4
0
        private void AnimatePiece(GazeAgumentedButton b, int row, int col, MoveStatus moveStatus)
        {
            double distance;         //distance the tile should move
            bool   isMoveHorizontal; //determine íf move is horizontal or vertical

            //get the direction the tile should move
            //Debug.Assert(moveStatus != MoveStatus.BadMove);
            if (moveStatus != MoveStatus.BadMove)
            {
                if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
                {
                    isMoveHorizontal = true;
                    // If direction is left then the distance = -1, Else direction is right and distance = 1
                    //distance = (moveStatus == MoveStatus.Left ? -1 : 1) * rootFE.Width;
                    distance = (moveStatus == MoveStatus.Left ? -1 : 1) * b.Width;
                }
                else
                {
                    isMoveHorizontal = false;
                    // If direction is up then the distance = 1, Else direction is down and distance = -1
                    //distance = (moveStatus == MoveStatus.Up ? -1 : 1) * rootFE.Height;
                    distance = (moveStatus == MoveStatus.Up ? -1 : 1) * b.Height;
                }

                // pull the animation after it's complete, because we move change Grid cells.
                DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.5), FillBehavior.Stop);
                slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
                {
                    // Anonymous delegate -- invoke when done.
                    Clock clock = (Clock)sender2;
                    if (clock.CurrentState != ClockState.Active)
                    {
                        // remove the render transform and really move the piece in the Grid.
                        try
                        {
                            MovePiece(b, row, col);


                            _moveDirection        = moveStatus.ToString(); //get the move direction and the button number
                            _selectedButtonNumber = b.Content.ToString();
                            //_previousMove = _selectedButtonNumber;      //Get the current and previously selected buttons
                            //_previousTime = _currentTime;
                            _currentTime = DateTime.Now;            //Set the times when the move was made


                            PrintToTextFile();  //print data to text file
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                };

                TranslateTransform buttonTransform = new TranslateTransform(0, 0);
                b.RenderTransform = buttonTransform;


                //perform the actual slide animation
                DependencyProperty directionProperty = isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;
                //rootFE.RenderTransform.BeginAnimation(directionProperty, slideAnim);
                b.RenderTransform.BeginAnimation(directionProperty, slideAnim);
            }
        }
Example #5
0
        private void BConfig()
        {
            #region ROW 1
            GazeAgumentedButton _00 = new GazeAgumentedButton();
            _00.SetValue(Grid.RowProperty, 0);
            _00.SetValue(Grid.ColumnProperty, 0);
            _00.Content = "6";
            this.Children.Add(_00);

            GazeAgumentedButton _01 = new GazeAgumentedButton();
            _01.SetValue(Grid.RowProperty, 0);
            _01.SetValue(Grid.ColumnProperty, 1);
            _01.Content = "8";
            this.Children.Add(_01);

            GazeAgumentedButton _02 = new GazeAgumentedButton();
            _02.SetValue(Grid.RowProperty, 0);
            _02.SetValue(Grid.ColumnProperty, 2);
            _02.Content = "1";
            this.Children.Add(_02);
            #endregion

            #region ROW 2
            //GazeAgumentedButton _10 = new GazeAgumentedButton();
            //_10.SetValue(Grid.RowProperty, 1);
            //_10.SetValue(Grid.ColumnProperty, 0);
            //_10.Content = "5";
            //this.Children.Add(_10);

            GazeAgumentedButton _11 = new GazeAgumentedButton();
            _11.SetValue(Grid.RowProperty, 1);
            _11.SetValue(Grid.ColumnProperty, 1);
            _11.Content = "7";
            this.Children.Add(_11);

            GazeAgumentedButton _12 = new GazeAgumentedButton();
            _12.SetValue(Grid.RowProperty, 1);
            _12.SetValue(Grid.ColumnProperty, 2);
            _12.Content = "3";
            this.Children.Add(_12);
            #endregion

            #region ROW 3
            GazeAgumentedButton _20 = new GazeAgumentedButton();
            _20.SetValue(Grid.RowProperty, 2);
            _20.SetValue(Grid.ColumnProperty, 0);
            _20.Content = "5";
            this.Children.Add(_20);

            GazeAgumentedButton _21 = new GazeAgumentedButton();
            _21.SetValue(Grid.RowProperty, 2);
            _21.SetValue(Grid.ColumnProperty, 1);
            _21.Content = "4";
            this.Children.Add(_21);

            GazeAgumentedButton _22 = new GazeAgumentedButton();
            _22.SetValue(Grid.RowProperty, 2);
            _22.SetValue(Grid.ColumnProperty, 2);
            _22.Content = "2";
            this.Children.Add(_22);
            #endregion
        }
        private void TrialConfig()
        {
            #region ROW 1
            GazeAgumentedButton _00 = new GazeAgumentedButton();
            _00.SetValue(Grid.RowProperty, 0);
            _00.SetValue(Grid.ColumnProperty, 0);
            _00.Content = "1";
            this.Children.Add(_00);

            GazeAgumentedButton _01 = new GazeAgumentedButton();
            _01.SetValue(Grid.RowProperty, 0);
            _01.SetValue(Grid.ColumnProperty, 1);
            _01.Content = "2";
            this.Children.Add(_01);

            GazeAgumentedButton _02 = new GazeAgumentedButton();
            _02.SetValue(Grid.RowProperty, 0);
            _02.SetValue(Grid.ColumnProperty, 2);
            _02.Content = "3";
            this.Children.Add(_02);
            #endregion

            #region ROW 2
            GazeAgumentedButton _10 = new GazeAgumentedButton();
            _10.SetValue(Grid.RowProperty, 1);
            _10.SetValue(Grid.ColumnProperty, 0);
            _10.Content = "8";
            this.Children.Add(_10);

            //Button _11 = new Button();
            //_11.FontSize = 24;
            //_11.Style = buttonStyle;
            //_11.SetValue(Grid.RowProperty, 1);
            //_11.SetValue(Grid.ColumnProperty, 1);
            //_11.Content = "2";
            //this.Children.Add(_01);

            GazeAgumentedButton _12 = new GazeAgumentedButton();
            _12.SetValue(Grid.RowProperty, 1);
            _12.SetValue(Grid.ColumnProperty, 2);
            _12.Content = "4";
            this.Children.Add(_12);
            #endregion

            #region ROW 3
            GazeAgumentedButton _20 = new GazeAgumentedButton();
            _20.SetValue(Grid.RowProperty, 2);
            _20.SetValue(Grid.ColumnProperty, 0);
            _20.Content = "7";
            this.Children.Add(_20);

            GazeAgumentedButton _21 = new GazeAgumentedButton();
            _21.SetValue(Grid.RowProperty, 2);
            _21.SetValue(Grid.ColumnProperty, 1);
            _21.Content = "6";
            this.Children.Add(_21);

            GazeAgumentedButton _22 = new GazeAgumentedButton();
            _22.SetValue(Grid.RowProperty, 2);
            _22.SetValue(Grid.ColumnProperty, 2);
            _22.Content = "5";
            this.Children.Add(_22);
            #endregion
        }
        private void MovePiece(GazeAgumentedButton b, int row, int col)
        {
            //*** MOVE THE TILE, ASSUMING THE MOVE IS VALID***
            //Identify the cell to move

            PuzzleCell newPosition = _puzzleLogic.MovePiece(row, col);
            try
            {
                //change the position of the tile in the grid
                b.SetValue(Grid.ColumnProperty, newPosition.Col);
                b.SetValue(Grid.RowProperty, newPosition.Row);

                //increment moves by 1
                _moves++;

                //Once the piece has been moved, then allow the next piece to be moved
                _isProcessingButton = false;
                //this.IsEnabled = true;//enable the grid
            }
            catch (Exception ex)
            {
                MessageBox.Show("Movement error !!!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void AnimatePiece(GazeAgumentedButton b, int row, int col, MoveStatus moveStatus)
        {
            double distance; //distance the tile should move
            bool isMoveHorizontal; //determine íf move is horizontal or vertical

            //get the direction the tile should move
            //Debug.Assert(moveStatus != MoveStatus.BadMove);
            if (moveStatus != MoveStatus.BadMove)
            {
                if (moveStatus == MoveStatus.Left || moveStatus == MoveStatus.Right)
                {
                    isMoveHorizontal = true;
                    // If direction is left then the distance = -1, Else direction is right and distance = 1
                    //distance = (moveStatus == MoveStatus.Left ? -1 : 1) * rootFE.Width;
                    distance = (moveStatus == MoveStatus.Left ? -1 : 1) * b.Width;
                }
                else
                {
                    isMoveHorizontal = false;
                    // If direction is up then the distance = 1, Else direction is down and distance = -1
                    //distance = (moveStatus == MoveStatus.Up ? -1 : 1) * rootFE.Height;
                    distance = (moveStatus == MoveStatus.Up ? -1 : 1) * b.Height;
                }

                // pull the animation after it's complete, because we move change Grid cells.
                DoubleAnimation slideAnim = new DoubleAnimation(distance, TimeSpan.FromSeconds(0.5), FillBehavior.Stop);
                slideAnim.CurrentStateInvalidated += delegate(object sender2, EventArgs e2)
                {
                    // Anonymous delegate -- invoke when done.
                    Clock clock = (Clock)sender2;
                    if (clock.CurrentState != ClockState.Active)
                    {
                        // remove the render transform and really move the piece in the Grid.
                        try
                        {
                            MovePiece(b, row, col);

                            _moveDirection = moveStatus.ToString();   //get the move direction and the button number
                            _selectedButtonNumber = b.Content.ToString();
                            //_previousMove = _selectedButtonNumber;      //Get the current and previously selected buttons
                            //_previousTime = _currentTime;
                            _currentTime = DateTime.Now;            //Set the times when the move was made

                            PrintToTextFile();  //print data to text file
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                };

                TranslateTransform buttonTransform = new TranslateTransform(0, 0);
                b.RenderTransform = buttonTransform;

                //perform the actual slide animation
                DependencyProperty directionProperty = isMoveHorizontal ? TranslateTransform.XProperty : TranslateTransform.YProperty;
                //rootFE.RenderTransform.BeginAnimation(directionProperty, slideAnim);
                b.RenderTransform.BeginAnimation(directionProperty, slideAnim);
            }
        }
Example #9
0
 void gazePointTimer_Tick(object sender, EventArgs e)
 {
     _smoothGazePoint = _gazePoint; //Get the smooth gaze point
     GazeAgumentedButton.OnHitTest(_smoothGazePoint);
     // tbMouse.Text = _smoothGazePoint.X.ToString() + " : " + _smoothGazePoint.Y.ToString();
 }