/// <summary> /// Removes cars from a given line and attaches them to the locomotive /// </summary> /// <param name="line">The line that cars will be loaded from</param> /// <param name="amount">The amount of cars to load</param> public void LoadCarsFromLine(IDecrementableLine line, int amount) { // Do not load more cars than the locomotive's maximum capacity amount = amount > MaximumCapacity ? MaximumCapacity : amount; while (amount-- > 0) { var car = line.RemoveCar(); Slots.Add(car); } }
private IMovement MoveConvoy(IYardLocomotive locomotive, ILinesMap map, IDecrementableLine origin, IIncrementableLine destination, int amount) { locomotive.LoadCarsFromLine(origin, amount); var movement = new Movement(origin, destination, locomotive.Cars.AsEnumerable<INamed>().ToList()); map.UpdateDepths(origin as ISortingLine, -movement.Cars.Count()); locomotive.UnloadAllCarsIntoLine(destination); map.UpdateDepths(destination as ISortingLine, movement.Cars.Count()); return movement; }
private IMovement MoveConvoy(IYardLocomotive locomotive, ILinesMap map, IDecrementableLine origin, IIncrementableLine destination, int amount) { locomotive.LoadCarsFromLine(origin, amount); var movement = new Movement(origin, destination, locomotive.Cars.AsEnumerable <INamed>().ToList()); map.UpdateDepths(origin as ISortingLine, -movement.Cars.Count()); locomotive.UnloadAllCarsIntoLine(destination); map.UpdateDepths(destination as ISortingLine, movement.Cars.Count()); return(movement); }