1

I want to save very large text in a variable (SPACE INVADERS), How can I save that type of text in a variable? . I'm learning c # I need help please.

Code: ---------------------------------------------------------------------------------------------------------------------------

namespace SpaceInvaders2017
{
    class Program
    {
        struct AtribEnemigos {
            public string simbolo;
            public ConsoleColor color;
            public bool visible;
            public int posColInicial;
            public int posFilaInicial;
            public float x, y;

        }
        static int nombre;
        static AtribEnemigos Texto;
        public static void MenuJuego(){     
            Console.Clear();
            MoverNombreJuego();
        }
        public static void MoverNombreJuego()
        {
            Texto.color = ConsoleColor.DarkRed;
            Texto.posColInicial = 0;
            Texto.posFilaInicial = 0;
            Texto.x = Texto.posColInicial;
            Texto.y = Texto.posFilaInicial;
 //Error here------------------------
            Texto.simbolo = { "▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ ",
                              "░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ ",
                              "▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░"};
        }

        public static void PausaFotograma()
        {
            Thread.Sleep(40);
        }
        static void Main(string[] args)
        {
            MenuJuego();
            //Console.ReadKey();
            PausaFotograma();
        }
    }
}

Image with errors

Iván
  • 39
  • 6

2 Answers2

2

You can use the project resources in order to store texts.

  • Right click the project in the Solution Explorer and click "Properties".
  • Select the tab "Resources".
  • In the strings section enter a name for the resource and a value. (Increase the row height and column width for large texts).
  • Close the project properties.

enter image description here

Now you can write:

Texto.simbolo = Properties.Resources.SpaceInvadersTitle;

You will see that Visual Studio lists SpaceInvadersTitle in intellisense.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Very interesting, do you have to specify the project name -`myProjectName.Properties.Resources.SpaceInvadersTitle`, or you can use it without. I was reading [this](https://msdn.microsoft.com/en-us/library/7k989cfy(v=vs.90).aspx) – Stanley S Mar 18 '17 at 23:41
  • Great, works well and keeps the code cleaner. Thank you. – Iván Mar 18 '17 at 23:54
  • @StanleyS: The `Properties` word is part of the namespace. If you are already in the `myProjectName`, you can drop it. You could also add a `using myProjectName.Properties;` instead and then simply write `Resources.SpaceInvadersTitle`, where `Resources` is a class with static properties for all the resources. – Olivier Jacot-Descombes Mar 19 '17 at 00:06
1

You can use @ for multi-line string:

        Texto.simbolo = 
            @"▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ 
░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ 
▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░";

or join strings with + operator and add new lines explicitly:

Texto.simbolo =
    "▄▀▀ █▀▄ ▄▀▄ ▄▀▀ █▀▀ . ▀█▀ █▄░█ █░░░█ ▄▀▄ █▀▄ █▀▀ █▀▄ ▄▀▀ " + Environment.NewLine +
    "░▀▄ █▀░ █▄█ █░░ █▀▀ . ░█░ █▀██ ░█░█░ █▄█ █░█  █▀▀ █▀▄ ░▀▄ " + Environment.NewLine +
    "▀▀░ ▀░░ ▀░▀ ░▀▀ ▀▀▀ . ▀▀▀ ▀░░▀ ░░▀░░ ▀░▀ ▀▀░ ▀▀▀ ▀░▀ ▀▀░";
Damian
  • 2,752
  • 1
  • 29
  • 28