// Create a barrier locally and inform listening clients that it is in the game
 private void createBarriers()
 {
     for (int i = 0; i < 1; i++)
     {
         _tx1 = Content.Load<Texture2D>(@"Sprites\grassBlack");
         Barrier b = new Barrier(_tx1, Vector2.Zero, font, 1, 1.0f);
         b.position = new Vector2(
                         Utility.NextRandom((int)_worldBound.X - _tx1.Width),
                         Utility.NextRandom((int)_worldBound.Y - _tx1.Height));
         b.owner = player.clientID;
         _barriers.Add(b);
     }
     // Inform the opponents of the new barriers
     foreach (Barrier b in _barriers)
     {  if (b.owner == player.clientID)
             proxy.Invoke("setUpOpponentBarrier", new object[] { (int)b.position.X, (int)b.position.Y });
     }
 }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            int characterChoice = Utilities.Utility.NextRandom(1);
            myConnection = new HubConnection("http://*****:*****@"Backgrounds\sky_pissyellowstripes");
            font = Content.Load<SpriteFont>(@"SpriteFonts\message");
            _tx0 = Content.Load<Texture2D>(@"Sprites\body");
            _tx1 = Content.Load<Texture2D>(@"Sprites\body2");
            characterChoice = Utility.NextRandom(1);

            if (characterChoice == 0) // first player is stronger and slower
            {
                player = new Player(_tx0,
                                    Vector2.Zero, 5.0f, font, 1, 0.5f,_worldBound);
            }
            else if (characterChoice == 1) // first player is stronger and slower
            {
                player = new Player(_tx1,
                                    Vector2.Zero, 10.0f, font, 1, 0.5f,_worldBound);
            }

            _viewCentre = new Vector2(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);
            // Create a player in the current Viewport in the current client
            player.position =
                _viewCentre;
                //new Vector2(
                //                Utility.NextRandom(GraphicsDevice.Viewport.Width),
                //                Utility.NextRandom(GraphicsDevice.Viewport.Height));
            player.clientID = myConnection.ConnectionId;
            player.speed = characterSpeed[player.textureName];
            _playerCam = new Camera(Vector2.Zero, _worldBound);
            // request to join the game
            proxy.Invoke("join", new object[] { player.clientID, player.textureName, (int)player.position.X, (int)player.position.Y });
            proxy.On<int>("playerNumber", (n)
                 =>
                     {
                         player.playerId = "Player " + n.ToString();
                     }
                    );
            proxy.On<int>("opponentNumber", (n)
                 =>
            {
                if(opponent != null)
                opponent.playerId = "Player " + n.ToString();
            }
                );
            // recieve a Joined player and setup an opponent player for that player
            proxy.On<string, string, int, int>("opponentJoined", (JoinedId, CharacterName, x, y)
                 =>
            {
                    if (opponent == null && JoinedId != player.clientID)
                    {
                        Texture2D tx = Content.Load<Texture2D>(@"" + CharacterName);
                        opponent = new Opponent(tx,
                                    Vector2.Zero, characterStrength[CharacterName], font, 1, 0.5f);
                        opponent.position = new Vector2(x, y);
                        opponent.clientID = JoinedId;
                        opponent.speed = characterSpeed[opponent.textureName];
                        //opponent.playerId = "Player " + count.ToString();
                    // Add the first player to join all the clients as it had no others when started
                    proxy.Invoke("addMe", new object[] { player.clientID,
                                                player.textureName,
                                                (int)player.position.X, (int)player.position.Y });
                    }
                });
            // recieve an opponent moved
            proxy.On<int, int>("opponentMoved", (x, y)
                => {if(opponent!=null) opponent.position = new Vector2(x, y); });
            // recieve a tidy up after an opponent has left
            proxy.On("opponentLeft", ()
                => { opponent = null; });
            // recieve a setup setup message and setup the game and start to play
            proxy.On("setup", ()
                =>{ createCollectables();
                    createBarriers();
                    playing = true;
                });
            // recieve an opponents barrier
            proxy.On<int, int>("createOpponentBarrier", (x, y) =>
            {
                _tx1 = Content.Load<Texture2D>(@"Sprites\grassGreen");
                Barrier b = new Barrier(_tx1, Vector2.Zero, font, 1, 0.1f);
                b.position = new Vector2(x, y);
                b.owner = opponent.clientID;
                _barriers.Add(b);
            });
            // recieve an opponents collectable
            proxy.On<int, int>("createOpponentCollectable", (x, y) =>
            {
                _tx1 = Content.Load<Texture2D>(@"Sprites\bomb");
                Collectable c = new Collectable(_tx1, Vector2.Zero, font, 1, 0.1f);
                c.position = new Vector2(x, y);
                c.owner = opponent.clientID;
                _collectables.Add(c);
            });
            // recieve a Remove message and remove an opponents artifacts from this game
            proxy.On<string>("Remove", (OpponentID) =>
            {
                var collectablesTodelete = (from c in _collectables
                              where c.owner == OpponentID
                              select c).ToList();
                foreach (Collectable c in collectablesTodelete)
                {
                    _collectables.Remove(c);

                }
                var barriersTodelete = (from c in _barriers
                              where c.owner == OpponentID
                              select c).ToList();
                foreach (Barrier b in barriersTodelete)
                {
                    _barriers.Remove(b);

                }
            });

            // TODO: use this.Content to load your game content here
        }