Ejemplo n.º 1
0
        protected override bool Logic()
        {
            _gameField.ClearField();

            if (_ball.X == 2)
            {
                if (_ball.Y > _player1.Y - 3 && _ball.Y < _player1.Y + 3)
                {
                    _ball.SetDirection((Ball.Direction)_rand.Next(4, 7));
                }
            }

            if (_ball.X == _gameField.Width - 3)
            {
                if (_ball.Y > _player2.Y - 3 && _ball.Y < _player2.Y + 3)
                {
                    _ball.SetDirection((Ball.Direction)_rand.Next(1, 4));
                }
            }

            if (_ball.X == 0 || _ball.X == _gameField.Width - 1)
            {
                if (_ball.X == 0)
                {
                    _score2++;
                }
                else
                {
                    _score1++;
                }
                _player1.ResetPosition(1, _gameField.Height / 2);
                _player2.ResetPosition(_gameField.Width - 2, _gameField.Height / 2);
                _ball.ResetPosition(_gameField.Width / 2, _gameField.Height / 2);
            }



            if (_ball.Y == 0)
            {
                if (_ball.Dir == Ball.Direction.LeftUp)
                {
                    _ball.SetDirection(Ball.Direction.LeftDown);
                }
                else
                {
                    _ball.SetDirection(Ball.Direction.RightDown);
                }
            }

            if (_ball.Y == _gameField.Height - 1)
            {
                if (_ball.Dir == Ball.Direction.LeftDown)
                {
                    _ball.SetDirection(Ball.Direction.LeftUp);
                }
                else
                {
                    _ball.SetDirection(Ball.Direction.RightUp);
                }
            }

            _player1.Move();
            _player2.Move();
            _ball.Move();
            return(false);
        }