Question Needing help with Reading Files INTS

mumbot

Member
Joined
Oct 3, 2012
Messages
5
Programming Experience
3-5
Hello all CSharp coders,

i have started a 2D GameEngine in C# iv already done Color rendering etc but to create the map i want the program to read from a file called SD_ENGINE_gui.txt

the code below is the map grid

w = 1

f = 0

PHP:
 int[,] level = {
                        {w, w, w, w, w, w, w, w, w, w},
                        {w, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, w, f, w},
                        {w, f, f, f, f, f, f, w, f, w},
                        {w, w, w, f, f, f, f, w, w, w},
                        {w, f, w, f, f, f, f, f, f, w},
                        {w, f, w, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, w},
                        {w, f, f, f, f, f, f, f, f, w},
                        {w, w, w, w, w, w, w, w, w, w},
                           };

so i want the program to read that from the .txt file and any changes made in the .txt will change once restarting the .exe. i have tryed many ways to save int values but non work.

Can someone please help me :)
 
You could just use an Int32 or Int16 to store the data for each row and use the bits as the flags. You could work with a BitArray in code or just use bitwise AND (&), OR (|) and NOT (!) to get and set individual bits in the numbers.
 
This is what i have to read the text file but it keeps giving me errors with the ints even when its Int32 or Int16
PHP:
 try
            {
                using (StreamReader sr = new StreamReader("content/SD_ENGINE_gui"))
                {
                    level = sr.ReadToEnd();
                    Console.WriteLine(level);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(SD_ENGINE.ERROR);
                Console.WriteLine(e.Message);
            }
 
Keeping the nature of the errors a secret is not conducive to our helping you to solve them. I'd start with that file path though. Is that really the path to a text file?
 
Back
Top Bottom