Как я могу остановить анимацию на позиции курсора - PullRequest
0 голосов
/ 27 октября 2019

Спасибо за помощь в стилистике моих модов. Спасибо.

Код работает отлично. он начинает двигаться от верхней части cmd и медленно опускается к cmd. хорошая анимация для текста ASCII.

И есть моя проблема, я не могу понять, как остановить анимацию на экране, чтобы она не покидала экран.

Я новичок в c # V_V, это оченьсейчас тяжело.

Quelle

using System;

namespace Dotned.UI.Framework
{
    public class Arbit
    {

        public static void Main(String[] Args)
        {
            var arr = new[]
            {
                    @"      /$$$$$$                                      /$$     /$$       /$$                          ",
                    @"      /$$__  $$                                    | $$    | $$      |__/                         ",
                    @"     | $$  \__/  /$$$$$$  /$$$$$$/$$$$   /$$$$$$  /$$$$$$  | $$$$$$$  /$$ /$$$$$$$   /$$$$$$      ", 
                    @"     |  $$$$$$  /$$__  $$| $$_  $$_  $$ /$$__  $$|_  $$_/  | $$__  $$| $$| $$__  $$ /$$__  $$     ", 
                    @"      \____  $$| $$  \ $$| $$ \ $$ \ $$| $$$$$$$$  | $$    | $$  \ $$| $$| $$  \ $$| $$  \ $$     ", 
                    @"      /$$  \ $$| $$  | $$| $$ | $$ | $$| $$_____/  | $$ /$$| $$  | $$| $$| $$  | $$| $$  | $$     ", 
                    @"     |  $$$$$$/|  $$$$$$/| $$ | $$ | $$|  $$$$$$$  |  $$$$/| $$  | $$| $$| $$  | $$|  $$$$$$$     ", 
                    @"      \______/  \______/ |__/ |__/ |__/ \_______/   \___/  |__/  |__/|__/|__/  |__/ \____  $$     ", 
                    @"                                                                                    /$$  \ $$     ",
                    @"                                                                                   |  $$$$$$/     ", 
                    @"                                                                                    \______/      ",           
            };
            Console.WindowWidth = 160;
            Console.WriteLine("\n\n");
            foreach(string line in arr )
                Console.WriteLine(line);
            Console.ReadKey();

        }
    }
}

.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace Dotned.UI.Framework
{
    public class Arbit
    {

        static void ConsoleDraw(IEnumerable<string> lines, int x, int y)
        {
            if (x > Console.WindowWidth) return;
            if (y > Console.WindowHeight) return;

            var trimLeft = x < 0 ? -x : 0;
            int index = y;

            x = x < 0 ? 0 : x;
            y = y < 0 ? 0 : y;

            var linesToPrint =
                from line in lines
                let currentIndex = index++
                where currentIndex > 0 && currentIndex < Console.WindowHeight
                select new
                {
                    Text = new String(line.Skip(trimLeft).Take(Math.Min(Console.WindowWidth - x, line.Length - trimLeft)).ToArray()),
                    X = x,
                    Y = y++
                };

            Console.Clear();
            foreach (var line in linesToPrint)
            {
                Console.SetCursorPosition(line.X, line.Y);
                Console.Write(line.Text);
            }
        }
        public static void Main(String[] Args)
        {
            var arr = new[]
            {
                    @"      /$$$$$$                                      /$$     /$$       /$$                          ",
                    @"      /$$__  $$                                    | $$    | $$      |__/                         ",
                    @"     | $$  \__/  /$$$$$$  /$$$$$$/$$$$   /$$$$$$  /$$$$$$  | $$$$$$$  /$$ /$$$$$$$   /$$$$$$      ", 
                    @"     |  $$$$$$  /$$__  $$| $$_  $$_  $$ /$$__  $$|_  $$_/  | $$__  $$| $$| $$__  $$ /$$__  $$     ", 
                    @"      \____  $$| $$  \ $$| $$ \ $$ \ $$| $$$$$$$$  | $$    | $$  \ $$| $$| $$  \ $$| $$  \ $$     ", 
                    @"      /$$  \ $$| $$  | $$| $$ | $$ | $$| $$_____/  | $$ /$$| $$  | $$| $$| $$  | $$| $$  | $$     ", 
                    @"     |  $$$$$$/|  $$$$$$/| $$ | $$ | $$|  $$$$$$$  |  $$$$/| $$  | $$| $$| $$  | $$|  $$$$$$$     ", 
                    @"      \______/  \______/ |__/ |__/ |__/ \_______/   \___/  |__/  |__/|__/|__/  |__/ \____  $$     ", 
                    @"                                                                                    /$$  \ $$     ",
                    @"                                                                                   |  $$$$$$/     ", 
                    @"                                                                                    \______/      ",           
            };
            Console.WindowWidth = 160;
            Console.WriteLine("\n\n");
            var maxLength = arr.Aggregate(0, (max, line) => Math.Max(max, line.Length));
            var x = Console.BufferWidth / 2 - maxLength / 2;
            for (int y = -arr.Length; y < Console.WindowHeight + arr.Length; y++)
            {
                ConsoleDraw(arr, x, y);
                Thread.Sleep(100);
            }
            Console.ReadKey();
        }
    }
}
...