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; }
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; } }