Beispiel #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;
                DwellTimeButton b = e.Source as DwellTimeButton;  //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);
                    _buttonMoveStatus = moveStatus.ToString();  //Move status of the button

                    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;
                    } //
                }
            }         //_isprocessingButton
        }
Beispiel #2
0
 void gazePointTimer_Tick(object sender, EventArgs e)
 {
     _smoothGazePoint = _gazePoint; //Get the smooth gaze point
     tbMouse.Text     = _smoothGazePoint.X.ToString() + " : " + _smoothGazePoint.Y.ToString();
     if (DwellTimePuzzleGrid.IsProcessingButton == false)
     {
         DwellTimeButton.OnHitTest(_smoothGazePoint);
     }
 }
Beispiel #3
0
        private void MovePiece(DwellTimeButton 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 TrialConfig()
        {
            #region ROW 1
            DwellTimeButton _00 = new DwellTimeButton();
            _00.SetValue(Grid.RowProperty, 0);
            _00.SetValue(Grid.ColumnProperty, 0);
            _00.Content = "1";
            this.Children.Add(_00);

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

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

            #region ROW 2
            DwellTimeButton _10 = new DwellTimeButton();
            _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);

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

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

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

            DwellTimeButton _22 = new DwellTimeButton();
            _22.SetValue(Grid.RowProperty, 2);
            _22.SetValue(Grid.ColumnProperty, 2);
            _22.Content = "5";
            this.Children.Add(_22);
            #endregion
        }
        private void MovePiece(DwellTimeButton 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(DwellTimeButton 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);
            _buttonMoveStatus = moveStatus.ToString();
            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);

                //play the click sound
                System.Media.SoundPlayer sp = new System.Media.SoundPlayer("Click.wav");
                sp.Play();
                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);
            }
        }
Beispiel #7
0
        private void AnimatePiece(DwellTimeButton 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);
            _buttonMoveStatus = moveStatus.ToString();
            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);

                //play the click sound
                System.Media.SoundPlayer sp = new System.Media.SoundPlayer("Click.wav");
                sp.Play();
                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);
            }
        }
Beispiel #8
0
        private void BConfig()
        {
            #region ROW 1
            DwellTimeButton _00 = new DwellTimeButton();
            _00.SetValue(Grid.RowProperty, 0);
            _00.SetValue(Grid.ColumnProperty, 0);
            _00.Content = "6";
            this.Children.Add(_00);

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

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

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

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

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

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

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

            DwellTimeButton _22 = new DwellTimeButton();
            _22.SetValue(Grid.RowProperty, 2);
            _22.SetValue(Grid.ColumnProperty, 2);
            _22.Content = "2";
            this.Children.Add(_22);
            #endregion
        }