/// <summary>
 /// Effectue une action dans un contexte
 /// </summary>
 /// <param name="x">Abscisse</param>
 /// <param name="y">Ordonnée</param>
 public void doContext(int x, int y)
 {
     if (this._currentSel != null)
     {
         UdpAdapter udpa = new UdpAdapter();
         Protocol_handler ph = new Protocol_handler();
         Point p = PointConverter.ToServerPoint(new Point(
             (x - (int)Math.Floor(this._pool.getMap().Position.X)),
             (y - (int)Math.Floor(this._pool.getMap().Position.Y))
         ));
         foreach (Drawable d in this._pool.getEntities())
         {
             if (d.Contains(p))
             {
                 if (d.Name == "mineral"
                     || d.Name == "richmineral"
                     || d.Name == "vespene")
                 {
                     udpa.send(ph.Unit_collect(this._currentSel, d));
                 }
                 else
                 {
                     udpa.send(ph.Unit_attack(this._currentSel, d));
                 }
                 return;
             }
         }
         udpa.send(ph.Unit_move(this._currentSel, p));
     }
 }
 private void _updateResources()
 {
     IProtocolAdapter ipa = new UdpAdapter();
     Protocol_handler ph = new Protocol_handler();
     ipa.send(ph.Player_getressources());
     int crystal, pop, popmax, vespen;
     ph.Unit_receiveRessources((Byte[])ipa.receive(), out crystal, out pop, out popmax, out vespen);
     this._playerinfo.Crystals = crystal;
     this._playerinfo.Gas = vespen;
     this._playerinfo.Pop = pop;
     this._playerinfo.PopMax = popmax;
 }
        /// <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);
            Protocol_handler protocol = new Protocol_handler();
            UdpAdapter udpa = new UdpAdapter();
            udpa.send(protocol.Unit_getAll());
            List<Sprite> entityList;
            protocol.Entity_receivelist((Byte[])udpa.receive(), out entityList);
            List<Sprite> resources;
            udpa.send(protocol.Ressources_getAll());
            protocol.Entity_receivelist((Byte[])udpa.receive(), out resources);
            entityList.AddRange(resources);
            // Chargement de la map
            Sprite map = new Sprite(new Vector2(0, 0), null);
            map.setPath("map");
            // Chargement du HUD
            Sprite hud = new Sprite(new Vector2(0, 289), null);
            hud.setPath("hud");
            // Chargement des boutons
            List<Sprite> buttonList = new List<Sprite>();

            // TODO: use this.Content to load your game content here
            _graphics.loadGame(entityList, map, hud, this._playerinfo, buttonList, out this._pool);
        }
 /// <summary>
 /// Mets à jour les positions
 /// </summary>
 private void _updateLocation()
 {
     UdpAdapter udpa = new UdpAdapter();
     Protocol_handler ph = new Protocol_handler();
     List<Sprite> entityList;
     List<Sprite> resources;
     udpa.send(ph.Unit_getAll());
     ph.Entity_receivelist((Byte[])udpa.receive(), out entityList);
     udpa.send(ph.Ressources_getAll());
     ph.Entity_receivelist((Byte[])udpa.receive(), out resources);
     entityList.AddRange(resources);
     List<Drawable> dl = this._pool.getEntities();
     for (int i = 0; i < entityList.Count(); ++i)
     {
         int j = 0;
         for (; j < dl.Count() ; ++j)
         {
             if (dl[j].getId() == entityList[i].getId())
             {
                 Point real_loc = PointConverter.ToClientPoint(new Point((int)entityList[i].ServerLoc.X, (int)entityList[i].ServerLoc.Y));
                 dl[j].Location = new Point((int)entityList[i].ServerLoc.X, (int)entityList[i].ServerLoc.Y);
                 dl[j].Position = new Vector2((float)-real_loc.X, (float)-real_loc.Y);
                 break;
             }
         }
         if (j >= dl.Count())
         {
             this._pool.loadEntity(entityList[i]);
         }
     }
     for (int i = 0; i < dl.Count(); ++i)
     {
         int j = 0;
         for (; j < entityList.Count(); ++j)
         {
             if (dl[i].getId() == entityList[j].getId())
             {
                 break;
             }
         }
         if (j >= entityList.Count())
         {
             this._pool.getEntities().RemoveAt(i);
         }
     }
 }
        /// <summary>
        /// Sélection d'une unité
        /// </summary>
        /// <param name="x">Abscisse</param>
        /// <param name="y">Ordonnée</param>
        public void selectEntity(int x, int y)
        {
            Point p = PointConverter.ToServerPoint(new Point(
                (x - (int)Math.Floor(this._pool.getMap().Position.X)),
                (y - (int)Math.Floor(this._pool.getMap().Position.Y))
            ));
            foreach (Drawable d in this._pool.getEntities())
            {
                if (d.Contains(p))
                {
                    this._currentSel = d;
                    return;
                }
            }

            if (this._currentSel != null)
            {
                if (Entities.mutate(this._currentSel.Name, x, y))
                {
                    UdpAdapter udpa = new UdpAdapter();
                    Protocol_handler ph = new Protocol_handler();
                    udpa.send(ph.Unit_mutation(this._currentSel, "zergling"));
                    return;
                }
            }
            this._currentSel = null;
        }