Esempio n. 1
0
        public TrainTrack Parse(XYCoord coord, char input)
        {
            TrainTrack trackNorth;
            TrainTrack trackWest;

            AllPositions.TryGetValue(new XYCoord(coord.X, coord.Y - 1), out trackNorth);
            AllPositions.TryGetValue(new XYCoord(coord.X - 1, coord.Y), out trackWest);

            TrainTrack newTrack = null;

            switch (input)
            {
            case '|': newTrack = new NorthSouth(coord, trackNorth); break;

            case '\\': newTrack = new Corner(coord, trackNorth, trackWest); break;

            case '/': newTrack = new Corner(coord, trackNorth, trackWest); break;

            case '-': newTrack = new EastWest(coord, trackWest); break;

            case '+': newTrack = new Intersection(coord, trackNorth, trackWest); break;
            }

            AllPositions.Add(coord, newTrack);

            return(newTrack);
        }
Esempio n. 2
0
        private void Parse(TrackFactory factory, int x, int y, char input)
        {
            var coord = new XYCoord(x, y);

            Cart       cart  = null;
            TrainTrack track = null;

            switch (input)
            {
            case '<': cart = new Cart(coord, Direction.West); input = '-'; break;

            case '>': cart = new Cart(coord, Direction.East); input = '-'; break;

            case '^': cart = new Cart(coord, Direction.North); input = '|'; break;

            case 'v': cart = new Cart(coord, Direction.South); input = '|'; break;
            }

            if (input != ' ')
            {
                track = factory.Parse(coord, input);
            }

            if (cart != null)
            {
                Carts.Add(cart);
                cart.track = track;
            }
        }
Esempio n. 3
0
 public void Link(TrainTrack track, Direction direction, bool backLink)
 {
     Neighbours[direction] = track;
     if (backLink)
     {
         track.Link(this, direction.Opposite(), false);
     }
 }
Esempio n. 4
0
 public Corner(XYCoord coord, TrainTrack north, TrainTrack west) : base(coord, north, west)
 {
     if (west is EastWest || west is Intersection)
     {
         Link(west, Direction.West, true); HasWest = true;
     }
     if (north is NorthSouth || north is Intersection)
     {
         Link(north, Direction.North, true); HasNorth = true;
     }
 }
Esempio n. 5
0
        public TrainTrack(XYCoord coord, TrainTrack north, TrainTrack west)
        {
            this.coord = coord;
            Neighbours = new Dictionary <Direction, TrainTrack>();

            if (north != null)
            {
                Link(north, Direction.North, true);
            }
            if (west != null)
            {
                Link(west, Direction.West, true);
            }
        }
Esempio n. 6
0
 public Intersection(XYCoord coord, TrainTrack north, TrainTrack west) : base(coord, north, west)
 {
 }
Esempio n. 7
0
 public EastWest(XYCoord coord, TrainTrack west) : base(coord, null, west)
 {
 }
Esempio n. 8
0
 public NorthSouth(XYCoord coord, TrainTrack north) : base(coord, north, null)
 {
 }