예제 #1
0
 public Cart(BaseTrack track)
 {
     IsFull   = true;
     PlacedOn = track;
     PlacedOn.Put(this);
     HasUnloaded = false;
 }
예제 #2
0
 public virtual bool MovePossible()
 {
     if (NextTrack is JoinTrack)
     {
         BaseTrack t = null;
         ((JoinTrack)NextTrack).PreviousTracks.TryGetValue(((JoinTrack)NextTrack).CurrentDirection, out t);
         if (!t.Equals(this))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #3
0
 public void FindNextTrack()
 {
     foreach (Track s in SurroundingTracks.Values)
     {
         if (s is BaseTrack)
         {
             if (((BaseTrack)s).NextTrack == null)
             {
                 this.NextTrack = (BaseTrack)s;
                 return;
             }
         }
     }
 }
예제 #4
0
        public override void Switch()
        {
            BaseTrack temp = NextTrack;

            NextTrack       = SecondNextTrack;
            SecondNextTrack = temp;

            if (CurrentDirection.Equals(Direction.UP))
            {
                CurrentDirection = Direction.DOWN;
            }
            else
            {
                CurrentDirection = Direction.UP;
            }
        }
예제 #5
0
        public override void Switch()
        {
            BaseTrack previousTrack = null;

            PreviousTracks.TryGetValue(CurrentDirection, out previousTrack);

            if (CurrentDirection.Equals(Direction.UP))
            {
                CurrentDirection = Direction.DOWN;
            }
            else
            {
                CurrentDirection = Direction.UP;
            }

            PreviousTracks.TryGetValue(CurrentDirection, out previousTrack);
            previousTrack.NextTrack = this; //Tell track in current direction it has a next track        }
        }
예제 #6
0
        public void AddTrack(int i, int j, char c, Track[,] map)
        {
            switch (c)
            {
            case '-':
                if (i == 4 && j == 0)
                {
                    map[i, j] = new FinalTrack(c);
                }
                else
                {
                    map[i, j] = new BaseTrack(c);
                }
                break;

            case '!':
                _numOfSwitches++;
                if (!(map[i, j - 1].GetSymbol().Equals('-')))
                {
                    map[i, j] = new JoinTrack(_numOfSwitches, Direction.DOWN);
                }
                else
                {
                    map[i, j] = new ForkTrack(_numOfSwitches, Direction.DOWN);
                }
                break;

            case '¡':
                _numOfSwitches++;
                if (!(map[i, j - 1].GetSymbol().Equals('-')))
                {
                    map[i, j] = new JoinTrack(_numOfSwitches, Direction.UP);
                }
                else
                {
                    map[i, j] = new ForkTrack(_numOfSwitches, Direction.DOWN);
                }
                break;

            case '=':
                map[i, j] = new HoldingTrack(c);
                break;

            case 'K':
                map[i, j] = new DockTrack(c, _waterAtDock);
                break;

            case 'A':
            case 'B':
            case 'C':
                map[i, j] = new Warehouse(c);
                break;

            case ' ':
                map[i, j] = new SpaceTrack(c);
                break;

            case '0':
                _waterAtDock      = new WaterTrack(':');
                Ship              = new Ship(_waterAtDock);
                _waterAtDock.Ship = Ship;
                map[i, j]         = _waterAtDock;
                break;

            case ':':
            case '~':
                map[i, j] = new WaterTrack(c);
                break;

            default:
                break;
            }
        }
예제 #7
0
        public void ConnectBaseTracks()
        {
            List <Warehouse> warehouses = GetWarehouses();

            foreach (Warehouse w in warehouses)
            {
                bool      finalReached = false;
                BaseTrack currentTrack = w;
                while (true)
                {
                    finalReached = false;
                    foreach (Track s in currentTrack.SurroundingTracks.Values)
                    {
                        if (s is BaseTrack)
                        {
                            if (currentTrack is JoinTrack)
                            {
                                Track b = null;
                                currentTrack.SurroundingTracks.TryGetValue(Direction.RIGHT, out b);
                                currentTrack.NextTrack = (BaseTrack)b;
                                currentTrack           = currentTrack.NextTrack;
                                break;
                            }
                            else if (currentTrack is ForkTrack)
                            {
                                Track b = null;

                                if (((ForkTrack)currentTrack).HasBeenPassed)
                                {
                                    currentTrack.SurroundingTracks.TryGetValue(((ForkTrack)currentTrack).OppositeDirection, out b);
                                    ((ForkTrack)currentTrack).SecondNextTrack = (BaseTrack)b;
                                    currentTrack = ((ForkTrack)currentTrack).SecondNextTrack;
                                }
                                else
                                {
                                    currentTrack.SurroundingTracks.TryGetValue(((ForkTrack)currentTrack).CurrentDirection, out b);
                                    currentTrack.NextTrack = (BaseTrack)b;
                                    ((ForkTrack)currentTrack).HasBeenPassed = true;
                                    currentTrack = currentTrack.NextTrack;
                                }
                                break;
                            }
                            else if (s is JoinTrack)
                            {
                                Track b = null;
                                currentTrack.SurroundingTracks.TryGetValue(Direction.LEFT, out b);
                                if (!(s.Equals((BaseTrack)b)))
                                {
                                    currentTrack.SurroundingTracks.TryGetValue(Direction.UP, out b);
                                    if (s.Equals(b))
                                    {
                                        ((JoinTrack)s).PreviousTracks.Add(Direction.DOWN, currentTrack);
                                    }
                                    else
                                    {
                                        ((JoinTrack)s).PreviousTracks.Add(Direction.UP, currentTrack);
                                    }
                                    currentTrack.NextTrack = (BaseTrack)s;
                                    currentTrack           = currentTrack.NextTrack;
                                    break;
                                }
                            }
                            else if (((BaseTrack)s).NextTrack != null) // if track already is assigned with a nexttrack
                            {
                                if (currentTrack.NextTrack != null && currentTrack.NextTrack.Equals(s))
                                {
                                    currentTrack = currentTrack.NextTrack;
                                    break;
                                }
                                else if (s is HoldingTrack)
                                {
                                    break;
                                }
                            }
                            else if (((BaseTrack)s).NextTrack == null && (!(s is Warehouse)))
                            {
                                currentTrack.NextTrack = (BaseTrack)s;
                                currentTrack           = currentTrack.NextTrack;
                                if (s is FinalTrack)
                                {
                                    finalReached = true;
                                }
                                break;
                            }
                        }
                        if (finalReached == true)
                        {
                            break;
                        }
                    }
                    if (finalReached == true || (!(currentTrack.SurroundingTracks.ContainsKey(Direction.LEFT)) && !(currentTrack is Warehouse)))
                    {
                        break; //go to next warehouse
                    }
                }
            }
        }