Ejemplo n.º 1
0
 /// <summary>
 /// Move nb cars to another BasicLine (By 3 max)
 /// </summary>
 /// <param name="moveTo">BasicLine to move the cars to</param>
 /// <param name="nb">number of cars to move</param>
 public void Move(BasicLine moveTo, int nb)
 {
     int num;
     while ((num = Math.Min(nb, 3)) > 0)
     {
         nb -= num;
         string str = Cars.Substring(0, num);
         Console.WriteLine($"Move {num} car ({str}) from {Name} to {moveTo.Name}.");
         Cars = Cars.Substring(num);
         moveTo.Cars = str + moveTo.Cars;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// CTOR No blocking
        /// </summary>
        /// <param name="path">path of the input file to use</param>
        /// <param name="c">car to find</param>
        public YardMaster(string path, char c)
        {
            _trainLine = new BasicLine();
            _lines = new List<YardLine>();

            if (!File.Exists(path))
                throw new FileNotFoundException(path + " is not found");
            int index = 0;
            using (StreamReader sr = new StreamReader(path))
            {
                while (sr.Peek() >= 0)
                {
                    _lines.Add(new YardLine(c, sr.ReadLine(), index++));
                }
            }
            if (_lines.Count() != 6)
                throw new InvalidDataException("The input file doesn't provide 6 lines");
        }