Example #1
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;
            }
        }
Example #2
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);
        }
Example #3
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;
     }
 }
Example #4
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);
            }
        }
Example #5
0
 public Intersection(XYCoord coord, TrainTrack north, TrainTrack west) : base(coord, north, west)
 {
 }
Example #6
0
 public EastWest(XYCoord coord, TrainTrack west) : base(coord, null, west)
 {
 }
Example #7
0
 public NorthSouth(XYCoord coord, TrainTrack north) : base(coord, north, null)
 {
 }
Example #8
0
 public Cart(XYCoord start, Direction facing)
 {
     cartCoords.Add(start);
     this.Facing   = facing;
     TurnDirection = TurnLeft.Singleton;
 }
Example #9
0
 public static void RemoveFrom(XYCoord coord)
 {
     cartCoords.Remove(coord);
 }