/// <summary> /// 房间置换数据 /// </summary> public static void ExchangeCanvans(List <RoomGrid> l1, List <RoomGrid> l1MoveTo, List <RoomGrid> l2, List <RoomGrid> l2MoveTo) { if (l1 == null || l2 == null) { return; } //if(l1.Count != l2.Count) // return ; List <RoomGrid> lTemp1 = new List <RoomGrid>(); //交换数据 int nRoomGrid1Count = l1.Count; for (int nRoomGrid1Cnt = 0; nRoomGrid1Cnt < nRoomGrid1Count; nRoomGrid1Cnt++) { RoomGrid R = l1[nRoomGrid1Cnt]; if (l2MoveTo.Contains(R)) { RoomGrid rTemp = l1[nRoomGrid1Cnt]; R = new RoomGrid(); R.CopyPutData(rTemp); rTemp.EmptyRoomGrid(); RemovePutRoomGrid(rTemp); } lTemp1.Add(R); } List <RoomGrid> lTemp2 = new List <RoomGrid>(); nRoomGrid1Count = l2.Count; for (int nRoomGrid1Cnt = 0; nRoomGrid1Cnt < nRoomGrid1Count; nRoomGrid1Cnt++) { RoomGrid R = l2[nRoomGrid1Cnt]; if (l1MoveTo.Contains(R)) { RoomGrid rTemp = l2[nRoomGrid1Cnt]; R = new RoomGrid(); R.CopyPutData(rTemp); rTemp.EmptyRoomGrid(); RemovePutRoomGrid(rTemp); } lTemp2.Add(R); } MoveCanvans(lTemp1, l1MoveTo); MoveCanvans(lTemp2, l2MoveTo); lTemp1.Clear(); lTemp2.Clear(); }
/// <summary> /// 移动房间 /// </summary> public static void MoveCanvans(List <RoomGrid> OldList, List <RoomGrid> NewList) { if (OldList == null || NewList == null) { return; } if (OldList.Count != NewList.Count) { return; } List <RoomGrid> Rdata = new List <RoomGrid>(); //先备份数据 for (int i = 0; i < OldList.Count; i++) { RoomGrid R = new RoomGrid(); R.CopyPutData(OldList[i]); OldList[i].EmptyRoomGrid(); Rdata.Add(R); } //继承数据 for (int i = 0; i < NewList.Count; i++) { NewList[i].InheritanceRoomGrid(Rdata[i]); } //先删除 for (int i = 0; i < OldList.Count; i++) { RemovePutRoomGrid(OldList[i]); } //后添加 for (int i = 0; i < NewList.Count; i++) { AddPutRoomGrid(NewList[i]); } }