コード例 #1
0
 private void SetIsForward(Bus bus, IHoldBuses station)
 {
     if (station == PlaceBuses.First().Key)
     {
         bus.IsForward = true;
     }
     if (station == PlaceBuses.Last().Key)
     {
         bus.IsForward = false;
     }
 }
コード例 #2
0
 private IHoldBuses NextPlace(IHoldBuses current, bool forward)
 {
     if (forward && current != PlaceBuses.Last().Key)
     {
         return(_NextStationForword(current));
     }
     else
     {
         return(_NextStationBackwards(current));
     }
 }
コード例 #3
0
        private void MoveBus(IHoldBuses from, IHoldBuses to, Bus bus)
        {
            from.RemoveBus(bus);
            PlaceBuses[from].Remove(bus);

            to.AddBus(bus);
            PlaceBuses[to].Add(bus);

            SetIsForward(bus, to);
            var d = bus.IsForward ? to.Delay + 1 : to.Delay;

            bus.SetDelay(d);

            Debug.WriteLine($"Bus #{bus} moved from station {from} to {to}");
        }
コード例 #4
0
        private void MoveBuses(IHoldBuses current, IList <Bus> buses)
        {
            for (int i = 0; i < buses.Count; i++)
            {
                if (!buses[i].Init())
                {
                    continue;
                }

                buses[i].Tick();
                if (buses[i].Next)
                {
                    var next = NextPlace(current, buses[i].IsForward);
                    MoveBus(current, next, buses[i]);
                    //buses[i].SetDelay(next);
                }
            }
        }
コード例 #5
0
        private IHoldBuses _NextStationBackwards(IHoldBuses current)
        {
            bool next = false;

            for (int i = PlaceBuses.Count - 1; i >= 0; i--)
            {
                if (next)
                {
                    return(PlaceBuses.ElementAt(i).Key);
                }
                if (PlaceBuses.ElementAt(i).Key == current)
                {
                    next = true;
                }
            }
            if (next)
            {
                return(PlaceBuses.First().Key);
            }
            throw new IndexOutOfRangeException();
        }
コード例 #6
0
        private IHoldBuses _NextStationForword(IHoldBuses current)
        {
            bool next = false;

            foreach (var sb in PlaceBuses)
            {
                if (next)
                {
                    return(sb.Key);
                }
                if (sb.Key == current)
                {
                    next = true;
                }
            }
            if (next)
            {
                return(PlaceBuses.First().Key);
            }
            throw new IndexOutOfRangeException();
        }