Пример #1
0
        public void LoadMap(int level)
        {
            Console.Clear();
            string       filePath = string.Format("Levels/Level{0}.txt", level);
            FileStream   fs       = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            StreamReader sr       = new StreamReader(fs); // открываем поток к файлу для чтения

            bool isPersonLoaded = false;
            bool isExitLoaded = false;
            int  x = 0, y = 0;

            person.ClearLocations(); // очистка всех обьектов(locations)
            exit.ClearLocations();
            wall.ClearLocations();
            Console.SetCursorPosition(50, 0);
            Console.WriteLine("Your Level: " + this.level);

            while (!sr.EndOfStream) // заполняем locations всех объектов
            {
                string line = sr.ReadLine();
                for (x = 0; x < line.Length; x++)
                {
                    if (line[x] == wall.GetLebel())
                    {
                        wall.AddPoint(new Point(x, y));
                    }
                    else if (line[x] == person.GetLebel() && !isPersonLoaded)
                    {
                        person.AddPoint(new Point(x, y));
                        isPersonLoaded = true;
                    }
                    else if (line[x] == exit.GetLebel() && !isExitLoaded)
                    {
                        exit.AddPoint(new Point(x, y));
                        isExitLoaded = true;
                    }
                }

                y++;
            }

            sr.Close();
            fs.Close();
        }
Пример #2
0
        public void LoadMap(int level)
        {
            Console.Clear();
            string       filePath = string.Format("Levels/Level{0}.txt", level);
            FileStream   fs       = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            StreamReader sr       = new StreamReader(fs);

            bool isPersonLoaded = false;
            bool isExitLoaded = false;
            int  x = 0, y = 0;

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();

                for (x = 0; x < line.Length; x++)
                {
                    if (line[x] == wall.GetLebel())
                    {
                        wall.AddPoint(new Point(x, y));
                    }
                    else if (line[x] == person.GetLebel() && !isPersonLoaded)
                    {
                        person.ClearLocations();
                        person.AddPoint(new Point(x, y));
                        isPersonLoaded = true;
                    }
                    else if (line[x] == exit.GetLebel() && !isExitLoaded)
                    {
                        exit.AddPoint(new Point(x, y));
                        isExitLoaded = true;
                    }
                }

                y++;
            }

            sr.Close();
            fs.Close();
        }