Esempio n. 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;
            }
        }
Esempio n. 2
0
        void ParseInput()
        {
            string resourceName = "Advent2018.Advent13.Input.txt";
            //resourceName = "Advent2018.Input.a13test.txt";
            var input = this.GetType().Assembly.GetManifestResourceStream(resourceName);

            var factory = new TrackFactory();

            Carts = new List <Cart>();

            using (var txt = new StreamReader(input))
            {
                int y = 0;
                while (!txt.EndOfStream)
                {
                    var line = txt.ReadLine();
                    for (int x = 0; x < line.Length; x++)
                    {
                        Parse(factory, x, y, line[x]);
                    }
                    y++;
                }
            }
        }