0

ユーザーが画面内の単語のアニメーションを制御できるようにするコンソール アプリを作成しようとしています。基本的に単語を表示し、ユーザーが押したキーに応じて単語が動き始めます。ほとんど機能していますが、何らかの理由で、ユーザーはキー leftArrow を 2 回または 3 回押す必要があるため、単語が左に移動し、他のキー upArrow、RightArrow、および downArrow についても同じことが起こっています。ユーザーはキーを 1 回だけ押す必要があり、単語はその方向に移動します。

画面の終わり(indexoutofrange)の例外にまだ対処しなければならないことはわかっていますが、それは手紙で行われます。まず、コントロールを機能させたいと思います。

助けてくれてありがとう

using System;
using System.Threading;

namespace Annimation
{
    class Program
    {
        static void Main(string[] args)
        {
            Boolean endOfCanvas = false;
            int x = 20, y = 25;
            ConsoleKeyInfo dir = new ConsoleKeyInfo();
            String word = "@@@@@@@@@@@";

            Console.WriteLine(word);

            do
            {
                do
                {
                    dir = Console.ReadKey(true);
                    while (Console.KeyAvailable == false)
                    {
                        if (dir.Key == ConsoleKey.DownArrow)
                        {
                            System.Console.Clear();
                            Console.SetCursorPosition(x, y);
                            Console.WriteLine(word);
                            Thread.Sleep(100);
                            Console.WriteLine("down");
                            y++;
                        }
                        else if (dir.Key == ConsoleKey.UpArrow)
                        {
                            System.Console.Clear();
                            Console.SetCursorPosition(x, y);
                            Console.WriteLine(word);
                            Thread.Sleep(100);
                            Console.WriteLine("up");
                            y--;
                        }
                        else if (dir.Key == ConsoleKey.LeftArrow)
                        {
                            System.Console.Clear();
                            Console.SetCursorPosition(x, y);
                            Console.WriteLine(word);
                            Thread.Sleep(100);
                            Console.WriteLine("Left");
                            x--;
                        }
                        else if (dir.Key == ConsoleKey.RightArrow)
                        {
                            System.Console.Clear();
                            Console.SetCursorPosition(x, y);
                            Console.WriteLine(word);
                            Thread.Sleep(100);
                            Console.WriteLine("Right");
                            x++;
                        }

                    }
                } while (Console.ReadKey(true).Key == ConsoleKey.DownArrow ||
                                Console.ReadKey(true).Key == ConsoleKey.UpArrow ||
                                Console.ReadKey(true).Key == ConsoleKey.RightArrow ||
                                Console.ReadKey(true).Key == ConsoleKey.LeftArrow);
            } while (!endOfCanvas);
        } 
    }
}
4

2 に答える 2