public bool ClickOnMySprite(MouseState mouseState)
 {
     for (int i = 0; i < playerList.Count; i++)
     {
         if (playerList[i].live) // nếu sprite còn sống
         {
             UserControlledSprite p = playerList[i];
             // nếu click trúng sprite
             if (p.boundsRectangle.Contains(new Point(mouseState.X, mouseState.Y)))
             {
                 if (!p.isMine)
                 {
                     return(false);
                 }
                 // sprite này đã được chọn từ trước (double click) => thì reset: coi như chưa chọn
                 if (selectedSprite == i)
                 {
                     selectedSprite = -1;
                     return(true);
                 }
                 else
                 {
                     selectedSprite = i;
                 }
                 return(true);
             }
         }
     }
     return(false);
 }
        public void MovingTowardMouse(GameTime gameTime, MouseState currentMouseState)
        {
            if (currentMouseState.LeftButton == ButtonState.Pressed && IsMouseInScreen(currentMouseState) &&
                lastMouseState.LeftButton == ButtonState.Released)
            {
                // nếu chuột click trên vùng trống
                if (!ClickOnMySprite(currentMouseState))
                {
                    for (int i = 0; i < playerList.Count; i++)
                    {
                        UserControlledSprite p = playerList[i];

                        // if p is selected before
                        if (selectedSprite == i)
                        {
                            selectedSprite = -1;
                            p.destination  = new Vector2(currentMouseState.X, currentMouseState.Y);
                            p.CheckOuOfScreen(Game.Window.ClientBounds);
                            p.isRunning = true;
                        }
                    }
                }
            }
            for (int i = 0; i < playerList.Count; i++)
            {
                UserControlledSprite p = playerList[i];
                if (p.isRunning)
                {
                    p.Update(gameTime);
                }
            }
        }
        public void ChekSelected()
        {
            double angle;

            for (int i = 0; i < playerList.Count; i++)
            {
                UserControlledSprite p = playerList[i];
                angle = Math.Atan2(p.currentDirection.X, p.currentDirection.Y) * 360 / (2 * Math.PI);

                //if (p.isRunning)
                //{
                //    if (p.evade > -1)
                //        p.image = Game.Content.Load<Texture2D>(@"Images\tranh");
                //    else
                //        p.image = Game.Content.Load<Texture2D>(@"Images\1384608133_bug");
                //}
                //else
                //{
                //    p.image = Game.Content.Load<Texture2D>(@"Images\1384505709_kbugbuster");

                //}
                //if (i == selectedSprite)
                //{
                //    p.image = Game.Content.Load<Texture2D>(@"Images\1384614265_Bug");
                //}
            }
        }
        public void ChangeImageByMovingDirection()
        {
            double angle;

            // đối với player
            for (int i = 0; i < playerList.Count; i++)
            {
                UserControlledSprite p = playerList[i];
                angle = Math.Atan2(p.currentDirection.X, p.currentDirection.Y) * 360 / (2 * Math.PI);

                if (Math.Abs(angle) < 45) // move down
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/down");
                }
                else if (Math.Abs(angle) > 135) // move up
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/up");
                }
                else if (angle > 45 && angle < 135) // move right
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/right");
                }
                else
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/left");
                }
            }
            // đối với enemy
            for (int i = 0; i < enemyList.Count; i++)
            {
                Enemy p = enemyList[i];
                angle = Math.Atan2(p.currentDirection.X, p.currentDirection.Y) * 360 / (2 * Math.PI);

                if (Math.Abs(angle) < 45) // move down
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/e-down");
                }
                else if (Math.Abs(angle) > 135) // move up
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/e-up");
                }
                else if (angle > 45 && angle < 135) // move right
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/e-right");
                }
                else
                {
                    p.image = Game.Content.Load <Texture2D>(@"Images/e-left");
                }
            }
        }
        public void Compatibility(GameTime gameTime)
        {
            for (int i = 0; i < playerList.Count; i++)
            {
                if (playerList[i].live)
                {
                    UserControlledSprite userControll = playerList[i];
                    if (userControll.isCompatibility(userControll))
                    {
                        if (checkCompatibility[i] < 1)
                        {
                            userControll.attack += coefficientCompatibility;
                            userControll.defend += coefficientCompatibility;
                            checkCompatibility[i]++;
                        }
                    }

                    if (userControll.isUnCompatibility(userControll))
                    {
                        if (checkUnCompatibility[i] < 1)
                        {
                            userControll.attack -= coefficientCompatibility;
                            userControll.defend -= coefficientCompatibility;
                            checkUnCompatibility[i]++;
                        }
                    }

                    if (!userControll.isCompatibility(userControll) &&
                        !userControll.isUnCompatibility(userControll))
                    {
                        userControll.attack     = userControll.copyAttack;
                        userControll.defend     = userControll.copyDefend;
                        checkCompatibility[i]   = 0;
                        checkUnCompatibility[i] = 0;
                    }
                }
            }
        }