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; } }
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); }
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; } }
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); } }
public Intersection(XYCoord coord, TrainTrack north, TrainTrack west) : base(coord, north, west) { }
public EastWest(XYCoord coord, TrainTrack west) : base(coord, null, west) { }
public NorthSouth(XYCoord coord, TrainTrack north) : base(coord, north, null) { }
public Cart(XYCoord start, Direction facing) { cartCoords.Add(start); this.Facing = facing; TurnDirection = TurnLeft.Singleton; }
public static void RemoveFrom(XYCoord coord) { cartCoords.Remove(coord); }