private void JoinGame(PlayerIndex playerIndex) {
            switch (playerIndex)
            {
                case PlayerIndex.One:
                    if (player1 == null)
                    {
                        Paddle paddle1 = new Paddle(PlayerIndex.One, this, ConvertUnits.ToSimUnits(screenWidth / 2.0f, screenHeight - 100.0f), ConvertUnits.ToSimUnits(150.0f), ConvertUnits.ToSimUnits(21.0f), ConvertUnits.ToSimUnits(screenWidth / 2.0f - sideMargin), world);
                        gameObjects.Add(paddle1);
                        player1 = new Player(this, paddle1, PlayerIndex.One);
                        SpawnBall(player1);

                        //gameObjects.Add(new Ball(player1, ConvertUnits.ToSimUnits(new Vector2(screenWidth / 2.0f, screenHeight - 400.0f)), ConvertUnits.ToSimUnits(10.0f), world));
                    }
                    else {
                        throw new InvalidOperationException("Player One is already in the game.");
                    }
                    break;
                case PlayerIndex.Two:
                    if (player2 == null)
                    {
                        Paddle paddle2 = new Paddle(PlayerIndex.Two, this, ConvertUnits.ToSimUnits(screenWidth / 2.0f, screenHeight - 100.0f), ConvertUnits.ToSimUnits(150.0f), ConvertUnits.ToSimUnits(21.0f), ConvertUnits.ToSimUnits(screenWidth / 2.0f - sideMargin), world);
                        gameObjects.Add(paddle2);
                        player2 = new Player(this, paddle2, PlayerIndex.Two);
                        SpawnBall(player2);

                        //gameObjects.Add(new Ball(player2, ConvertUnits.ToSimUnits(new Vector2(screenWidth / 2.0f, screenHeight - 400.0f)), ConvertUnits.ToSimUnits(10.0f), world));
                    }
                    else {
                        throw new InvalidOperationException("Player Two is already in the game.");
                    }
                    break;
                default:
                    break;
            }
        }
示例#2
0
 public Player(GameplayManager gm, Paddle paddle, PlayerIndex playerIndex) {
     this.gm = gm;
     this.paddle = paddle;
     this.playerIndex = playerIndex;
 }
示例#3
0
 public Player(GameplayManager gm, Paddle paddle, PlayerIndex playerIndex)
 {
     this.gm          = gm;
     this.paddle      = paddle;
     this.playerIndex = playerIndex;
 }