Exemple #1
0
        public AcceptJoinPacket()
            : base(PacketType.AcceptJoin)
        {
            Payload = new byte[sizeof(PaddleSide)];

            // Set a dfeault paddle of None
            Side = PaddleSide.None;
        }
Exemple #2
0
        /// <summary>
        /// Creates a new paddle of a certain type for a specific side.
        /// </summary>
        /// <param name="type">The type of the paddle to create.</param>
        /// <param name="paddleSide">The side where the paddle should be placed.</param>
        /// <returns>The new paddle instance as a <see cref="PaddleBase"/> object.</returns>
        public PaddleBase CreatePaddle(Type type, PaddleSide paddleSide)
        {
            Func <PaddleFactory, PaddleSide, PaddleBase> constructor;

            if (Constructors.TryGetValue(type, out constructor))
            {
                return(constructor.Invoke(this, paddleSide));
            }
            return(null);
        }
Exemple #3
0
 // Increase the score, update the score texts and check if there's a winner
 public void IncreaseScore(PaddleSide player)
 {
     if (player == PaddleSide.LEFT)
     {
         ++player1Score;
     }
     else
     {
         ++player2Score;
     }
     UpdateScoreTexts();
     CheckVictoryConditions();
 }
Exemple #4
0
        private PaddleBase CreateBasicAiPaddle(PaddleSide paddleSide)
        {
            ThrowExceptionWhenDisposed();

            return(new BasicAiPaddle(
                       _gameInfo,
                       _paddlePixel,
                       _actorRegistry,
                       paddleSide,
                       SettingsConstants.PaddleSize,
                       SettingsConstants.PaddleBoundsPadding,
                       SettingsConstants.PaddleSpeed));
        }
Exemple #5
0
        private PaddleBase CreatePlayerPaddle(PaddleSide paddleSide)
        {
            ThrowExceptionWhenDisposed();

            return(new PlayerPaddle(
                       _gameInfo,
                       _paddlePixel,
                       _settingsManager,
                       _inputManager,
                       paddleSide,
                       SettingsConstants.PaddleSize,
                       SettingsConstants.PaddleBoundsPadding,
                       SettingsConstants.PaddleSpeed));
        }
Exemple #6
0
        protected PaddleBase(GameInfo gameInfo, Texture2D texture, PaddleSide paddleSide, Vector2 size, Vector2 boundsPadding, float speed)
        {
            float xPosition = paddleSide == PaddleSide.Left
                ? boundsPadding.X
                : gameInfo.Bounds.Right - boundsPadding.X - size.X;

            float yPosition = gameInfo.Bounds.Height / 2F - size.Y / 2F;

            _texture      = texture;
            GameInfo      = gameInfo;
            PaddleSide    = paddleSide;
            Speed         = speed;
            Hitbox        = new RectangleF(xPosition, yPosition, size.X, size.Y);
            BoundsPadding = boundsPadding;
        }
Exemple #7
0
        public Paddle(SMALL_RECT playArea, short row, PaddleSide aSide, Terminal aTerm)
        {
            fPaddleHeight = 5;
            fPlayArea = playArea;
            fColor = ConsoleTextColor.White;
            fSide = aSide;
            fTerm = aTerm;
            
            short column;
            if (PaddleSide.Left == aSide)
                column = 0;
            else
                column = 79;

            fPosition = new COORD(column, row);
        }
Exemple #8
0
 // End a game
 // Name the winner to see on the game settings menu
 public void GameOver(PaddleSide winner)
 {
     if (ball == null)
     {
         return;
     }
     ball.PutBackAtCenter();
     if (winner == PaddleSide.LEFT)
     {
         winnerText.SetText("Last game winner: <color=#2932ff>Player 1</color>");
     }
     else
     {
         winnerText.SetText("Last game winner: <color=#ff2f35>Player 2</color>");
     }
     winnerText.gameObject.SetActive(true);
     newGameEvent.Invoke(); // Unity events so some logic can be modified directly in the editor
 }
Exemple #9
0
        // Resets the ball for a paddle to serve
        public void Reset(PaddleSide paddleSide)
        {
            // Pick a random side (left or right) for the ball to start if no side was specified
            if (paddleSide == PaddleSide.Undetermined)
            {
                paddleSide = (PaddleSide)_random.Next(1, 3);
            }

            float xPosition = 0F;  // The X position of the center of the ball to set
            float minAngle  = 0F;  // The minimum angle of the ball to set

            // Determine the base values for the position and angle
            switch (paddleSide)
            {
            case PaddleSide.Left:
                xPosition = _gameInfo.Bounds.Width * 0.25F;
                minAngle  = SettingsConstants.BallRightDirectionAngleStart;
                break;

            case PaddleSide.Right:
                xPosition = (_gameInfo.Bounds.Width * 0.75F) - Hitbox.Width;
                minAngle  = SettingsConstants.BallLeftDirectionAngleStart;
                break;
            }

            // Adjust the ball's position
            Hitbox.X = xPosition;
            Hitbox.Y = _gameInfo.Bounds.Height / 2F - Hitbox.Height / 2F;

            // Adjust the ball's angle
            float randomDegrees = _random.Next(0, SettingsConstants.BallAngleRange);

            Angle = minAngle + randomDegrees;

            IsResetting = true;
        }
Exemple #10
0
 public void IncreaseScorePlayer(PaddleSide player)
 {
     // Score is handled in the ScoreManager object so pass the information to it
     scoreManager.IncreaseScore(player);
 }
Exemple #11
0
 // Sets which side the paddle is
 public Paddle(PaddleSide side)
 {
     Side = side;
 }
Exemple #12
0
 public PlayerPaddle(GameInfo gameInfo, Texture2D texture, SettingsManager settingsManager, InputManager inputManager, PaddleSide paddleSide, Vector2 size, Vector2 boundsPadding, float speed)
     : base(gameInfo, texture, paddleSide, size, boundsPadding, speed)
 {
     _inputManager    = inputManager;
     _settingsManager = settingsManager;
 }
Exemple #13
0
 public BasicAiPaddle(GameInfo gameInfo, Texture2D texture, ActorRegistry actorRegistry, PaddleSide paddleSide, Vector2 size, Vector2 boundsPadding, float speed)
     : base(gameInfo, texture, paddleSide, size, boundsPadding, speed)
 {
     _actorRegistry = actorRegistry;
 }