Exemple #1
0
        public AnswerModel Solve()
        {
            AnswerModel answer = new AnswerModel();
            List <Star> stars  = new List <Star>();

            foreach (string line in _input)
            {
                Match match = _regex.Match(line);
                Star  star  = new Star(match);
                stars.Add(star);
            }

            int seconds = 0;

            while (true)
            {
                StarCordsDiff diff = GetBiggestDif(stars);

                if (diff.DifY + 1 == CHARSIZE)
                {
                    Draw(stars, diff);
                    Console.SetCursorPosition(0, CHARSIZE);
                    break;
                }
                seconds++;
                stars.ForEach(star => star.Tick());
            }

            Console.SetCursorPosition(0, CHARSIZE + 1);

            answer.PartA = "^";
            answer.PartB = seconds;
            return(answer);
        }
Exemple #2
0
        private void Draw(List <Star> stars, StarCordsDiff diff)
        {
            Console.Clear();
            int consolex = Math.Max(Console.WindowWidth, diff.DifX + 1);
            int consoleY = Math.Max(Console.WindowHeight, diff.DifY + 1);

            Console.SetBufferSize(consolex, consoleY);
            foreach (Star star in stars)
            {
                Console.SetCursorPosition(Math.Abs(star.X - diff.MinX), Math.Abs(star.Y - diff.MinY));
                Console.Write("#");
            }
        }