Ejemplo n.º 1
0
        public void LeaveState()
        {
            _playerOne = null;
            _playerTwo = null;
            _playerController.FinalizeController();

            if (GameWindow.GetGameWindow().Paused)
            {
                GameWindow.GetGameWindow().TogglePause();
            }
        }
Ejemplo n.º 2
0
        public void Update(Ball ball, Racquet left, Racquet right)
        {
            var ballVerGap    = 600f - ball.Size.Height;
            var racquetHorGap = right.Location.X - left.Location.X - left.Size.Width - ball.Location.X;
            var racquetVerGap = 600f - right.Size.Height;

            var decider = _random.Next(0, 100);

            if (_inGameState.PlayerTwoServing)
            {
                if (MathFunctions.Equals(_inGameState.PlayerTwoTargetHeight, right.Location.Y))
                {
                    _decidingService = true;
                }

                if (_decidingService)
                {
                    _inGameState.PlayerTwoTargetHeight = (right.Size.Height / 2f) + racquetVerGap * (decider / 100f);
                    _decidingService = false;
                }
            }
            else
            {
                _decidingService = true;

                if (decider > 4)
                {
                    return;
                }

                if (MathFunctions.EqualsOrLess(ball.Speed.X, 0))
                {
                    _inGameState.PlayerTwoTargetHeight = 300;
                }
                else
                {
                    var yDistance = ball.Location.Y + ball.Speed.Y * (racquetHorGap / ball.Speed.X);
                    var bounces   = Math.Truncate(yDistance / ballVerGap);
                    var even      = (bounces % 2) == 0;
                    var reminder  = yDistance % ballVerGap;

                    if (even)
                    {
                        _inGameState.PlayerTwoTargetHeight = reminder;
                    }
                    else
                    {
                        _inGameState.PlayerTwoTargetHeight = ballVerGap - reminder;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void EnterState()
        {
            _serviceSpeed   = 300f;
            _playerOneScore = 0;
            _playerTwoScore = 0;

            _ball      = new Ball(25f, new PointF(400f, 300f), 30f);
            _playerOne = new Racquet(500f, new PointF(50f, 400f), new SizeF(20f, 100f));
            _playerTwo = new Racquet(500f, new PointF(750f, 400f), new SizeF(20f, 100f));

            PlayerOneServing = true;
            PlayerTwoServing = false;

            _aiController.InitializeController(this);
            _playerController.InitializeController(this);
        }
Ejemplo n.º 4
0
        public void Add(RacquetDTO item)
        {
            Racquet racquet = new Racquet
            {
                RacquetId         = item.RacquetId,
                Title             = item.RacquetTitle,
                Photo             = item.Photo,
                Price             = item.Price,
                StringSurfaceArea = item.StringSurfaceArea,
                Mass           = item.Weight,
                Balance        = item.Balance,
                Available      = item.Available,
                ManufacturerId = item.ManufacturerId
            };

            repository.Add(racquet);
        }