Exemplo n.º 1
0
 public virtual void ChangePosition(ItemPosition ip, com.wd.free.item.ItemInventory toIn, int toX, int toY)
 {
     for (int i = ip.GetX(); i < ip.GetX() + ip.GetKey().GetGridWidth(); i++)
     {
         for (int j = ip.GetY(); j < ip.GetY() + ip.GetKey().GetGridHeight(); j++)
         {
             ins[j][i] = false;
         }
     }
     for (int i_1 = toX; i_1 < toX + ip.GetKey().GetGridWidth(); i_1++)
     {
         for (int j = toY; j < toY + ip.GetKey().GetGridHeight(); j++)
         {
             toIn.ins[j][i_1] = true;
         }
     }
     // System.err.println(ip.getKey().getKey() + " " + ip.getX() + ","
     // + ip.getY() + "->" + toX + "," + toY);
     ip.SetX(toX);
     ip.SetY(toY);
     if (ip.inventory != toIn)
     {
         posList.Remove(ip);
         toIn.posList.Add(ip);
     }
     ip.inventory = toIn;
 }
Exemplo n.º 2
0
        public virtual bool CanMoveTo(ItemPosition ip, com.wd.free.item.ItemInventory toIn, int toX, int toY)
        {
            bool can = true;

            TempSetPosition(ip, false);
            can = IsEmpty(toIn, toX, toY, ip.GetKey().GetGridWidth(), ip.GetKey().GetGridHeight());
            TempSetPosition(ip, true);
            return(can);
        }
Exemplo n.º 3
0
 private void TempSetPosition(com.wd.free.item.ItemInventory inventory, int x, int y, int w, int h, bool value)
 {
     for (int i = x; i < x + w; i++)
     {
         for (int j = y; j < y + h; j++)
         {
             inventory.ins[j][i] = value;
         }
     }
 }
Exemplo n.º 4
0
 private bool IsEmpty(com.wd.free.item.ItemInventory toIn, int x, int y, int w, int h)
 {
     for (int i = x; i < x + w; i++)
     {
         for (int j = y; j < y + h; j++)
         {
             if (i >= toIn.column || j >= toIn.row || toIn.ins[j][i])
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemplo n.º 5
0
        public virtual void ExchangeItemPosition(ItemPosition p1, ItemPosition p2)
        {
            for (int i = p1.GetX(); i < p1.GetX() + p1.GetKey().GetGridWidth(); i++)
            {
                for (int j = p1.GetY(); j < p1.GetY() + p1.GetKey().GetGridHeight(); j++)
                {
                    p1.inventory.ins[j][i] = false;
                }
            }
            for (int i_1 = p2.GetX(); i_1 < p2.GetX() + p2.GetKey().GetGridWidth(); i_1++)
            {
                for (int j = p2.GetY(); j < p2.GetY() + p2.GetKey().GetGridHeight(); j++)
                {
                    p2.inventory.ins[j][i_1] = false;
                }
            }
            for (int i_2 = p1.GetX(); i_2 < p1.GetX() + p2.GetKey().GetGridWidth(); i_2++)
            {
                for (int j = p1.GetY(); j < p1.GetY() + p2.GetKey().GetGridHeight(); j++)
                {
                    p1.inventory.ins[j][i_2] = true;
                }
            }
            for (int i_3 = p2.GetX(); i_3 < p2.GetX() + p1.GetKey().GetGridWidth(); i_3++)
            {
                for (int j = p2.GetY(); j < p2.GetY() + p1.GetKey().GetGridHeight(); j++)
                {
                    p2.inventory.ins[j][i_3] = true;
                }
            }
            int oldX = p1.GetX();
            int oldY = p1.GetY();

            p1.SetX(p2.GetX());
            p1.SetY(p2.GetY());
            p2.SetX(oldX);
            p2.SetY(oldY);
            if (p1.inventory != p2.inventory)
            {
                p1.inventory.posList.Remove(p1);
                p2.inventory.posList.Remove(p2);
                p1.inventory.posList.Add(p2);
                p2.inventory.posList.Add(p1);
                com.wd.free.item.ItemInventory temp = p1.inventory;
                p1.inventory = p2.inventory;
                p2.inventory = temp;
            }
        }