Beispiel #1
0
        /// <summary>
        /// Draws the game.  Please don't judge me.
        /// </summary>
        /// <param name="grid"></param>
        public static void Render(SnakeGrid grid)
        {
            int X = grid.Width;
            int Y = grid.Height;

            var playerPos  = player.GetPosition();
            var playerTail = player.GetTail();

            Console.SetCursorPosition(0, 0);
            Console.WriteLine(new string('=', X + 2));
            for (int cy = 0; cy < Y; cy++)
            {
                var row = new StringBuilder();
                row.Append(new string(' ', Y));

                foreach (var tail in playerTail)
                {
                    if (tail.Y == cy)
                    {
                        row[tail.X] = 'o';
                    }
                }

                if (playerPos.Y == cy)
                {
                    row[playerPos.X] = 'O';
                }

                if (grid.Apple.Y == cy)
                {
                    row[grid.Apple.X] = '@';
                }

                row.Insert(0, '=');
                row.Append('=');

                Console.WriteLine(row);
            }

            Console.WriteLine(new string('=', X + 2));

            Console.WriteLine($"{playerPos} {playerTail.Count()}   ");
        }