void MoveUnit(Unit Unit, MovementEventArgs E, bool Visible) { Tile tile = E.Tile; UnitView view = _UnitViews[Unit]; view.Move(E); view.SetAlpha(Visible ? (byte)255 : LAST_SEEN_ALPHA); var from = _Stacks.FirstOrDefault(i => i.Value.Contains(Unit)); StackView fromStack = from.Value; StackView toStack = _Stacks.FirstOrDefault(i => i.Key == tile).Value; if (toStack != null && toStack == fromStack) { return; } if (toStack == null) { toStack = new StackView(); _Stacks.Add(new KeyValuePair <Tile, StackView>(tile, toStack)); } toStack.Add(view); if (fromStack != null) { fromStack.Remove(Unit); if (fromStack.Units.Count() == 0) { _Stacks.Remove(from); } } }
void RemoveUnit(Unit Unit) { var from = _Stacks.FirstOrDefault(i => i.Value.Contains(Unit)); StackView fromStack = from.Value; if (fromStack != null) { fromStack.Remove(Unit); if (fromStack.Units.Count() == 0) { _Stacks.Remove(from); } } }