【问题标题】:Create Letters in C# and move them in Console在 C# 中创建字母并在控制台中移动它们
【发布时间】:2022-06-14 14:38:28
【问题描述】:

我需要创建一个程序,其中“H”和“S”写为“#”,移动、更改大小并在任何字母上随机着色。我必须使用 Console.SetCursorPosition() 但我不确定循环中的哪个位置。我在 for 循环中尝试过,但只移动了一行或不正确。

using System;

class Program
{
    static int reihe, spalte;
    static int size;

    static void Main(string[] args)
    {
        HS();
    }

    static void H()
    {
        for (reihe = 0; reihe < 7; reihe++)
        {
            for (spalte = 0; spalte < 7; spalte++)
            {
                if ((spalte == 1 || spalte == 5) || (reihe == 3 && spalte > 1 && spalte < 6))
                {
                    Console.Write("#");
                }
                else
                {
                }

                Console.Write(" ");
            }

            Console.WriteLine();
        }
    }

    static void S()
    {
        for (reihe = 0; reihe < 7; reihe++)
        {
            for (spalte = 0; spalte < 7; spalte++)
            {
                if (((reihe == 0 || reihe == 3 || reihe == 6) && spalte > 1 && spalte < 5) || (spalte == 1 && (reihe == 1 || reihe == 2 || reihe == 6)) || (spalte == 5 && (reihe == 0 || reihe == 4 || reihe == 5)))
                    Console.Write("#");
                else
                    Console.Write(" ");
            }

            Console.WriteLine();
        }
    }

    static void HS()
    {
        //Erzeugt 7 Reihen
        for (reihe = 0; reihe < 7; reihe++)
        {
            //Erzeugt 13 Spalten
            for (spalte = 0; spalte < 13; spalte++)
            {
                //Erzeugt HS in einer if-Bedingung **FALSCH** Das H muss in einer Bedingung produziert werden wie das S in einer eigenen if-bedingung.
                if (((spalte == 1 || spalte == 5)

                    || (spalte == 8 && (reihe == 1 || reihe == 2 || reihe == 6)))

                    || (spalte == 12 && ( reihe == 0 || reihe == 4 || reihe == 5))

                    || (reihe == 3 && (spalte == 2 || spalte == 3 || spalte == 4 || spalte == 9 || spalte == 10 || spalte == 11))

                    || (reihe == 0 && (spalte == 9 || spalte == 10 || spalte == 11))

                    || (reihe == 6 && (spalte == 8 || spalte == 9 || spalte == 10 || spalte == 11)))
                {

                    Console.ForegroundColor = ConsoleColor.Blue;   

                    Console.Write("#");

                }
                else
                {
                    Console.Write(" ");
                }
            }

            Console.WriteLine(" ");
        }
    }

    static void HSUpdated()
    {
    }

    static void SwitchHS()
    {
        for (reihe = 0; reihe < 7; reihe++)
        {
            for (spalte = 0; spalte < 12; spalte++)
            {
                if (((reihe == 0) && (spalte > 0 && spalte < 5)) || ((spalte == 0) && (reihe > 0 && reihe < 3)) || ((reihe == 3) && (spalte > 0 && spalte < 4)) || ((spalte == 4) && (reihe > 3 && reihe < 6)) || ((reihe == 6) && (spalte < 4))) 
                {
                    Console.Write("#");
                }
                else
                {
                    Console.Write(" ");
                }
            }

            Console.WriteLine();
        }
    }
}

【问题讨论】:

    标签: c# console letter


    【解决方案1】:

    在您的 HS() 函数中添加 Console.SetCursorPosition() for 循环之前,如果这不起作用,请将其放入您的 SwitchHS() 函数中。

    【讨论】:

      猜你喜欢
      • 2013-09-10
      • 2014-10-08
      • 1970-01-01
      • 2020-02-09
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 1970-01-01
      相关资源
      最近更新 更多