Ejemplo n.º 1
0
        public Room(string file, bool freeroam, ReplayRecorder recorder)
            : this()
        {
            freeroaming = freeroam;
            this.recorder = recorder;

            // Get level name
            levelName = file.Split('\\')[file.Split('\\').Length - 1].Replace(".srl", "");
            custom = true;

            SimpleAES decryptor = new SimpleAES();
            StreamReader levelReader = new StreamReader(file);
            string[] line;

            // Get level id
            levelID = levelReader.ReadLine();

            // Check if level will have a leaderboard
            canViewLeaderboards = decryptor.DecryptString(levelReader.ReadLine()) == "1";

            // Get level theme
            line = decryptor.DecryptString(levelReader.ReadLine()).Split(' ');
            Theme = FindTheme(line[0]);
            wallSet = new Tileset(Game1.tileSet[(int)Theme], 32, 32, 3, 3);

            // Get room dimensions
            line = decryptor.DecryptString(levelReader.ReadLine()).Split(' ');
            roomWidth = int.Parse(line[0]);
            roomHeight = int.Parse(line[1]);

            // Get goal times
            goals = new int[3];
            line = decryptor.DecryptString(levelReader.ReadLine()).Split(' ');
            for (int i = 0; i < 3; i++)
                goals[i] = int.Parse(line[i]);

            // Get objects and tiles
            while (!levelReader.EndOfStream)
            {
                string s = levelReader.ReadLine();
                if (s.Length > 0)
                {
                    line = decryptor.DecryptString(s).Split(' ');
                    ParseObjectOrTile(line, freeroam);
                }
            }
            levelReader.Dispose();

            BuildTiles();

            // Generate zipline poles
            foreach (ZipLine z in ziplines)
                z.SetPoles(this);

            // Get current record for this level
            FindRecord(decryptor);

            UpdateViewBox(false);
        }
Ejemplo n.º 2
0
        public Room(string[] lines, bool freeroam, ReplayRecorder recorder)
            : this()
        {
            freeroaming = freeroam;
            this.recorder = recorder;

            SimpleAES decryptor = new SimpleAES();
            string[] line;

            // Get level name
            levelName = lines[0];
            custom = false;

            // Get level id
            levelID = lines[1];

            // Check if level will have a leaderboard
            canViewLeaderboards = decryptor.DecryptString(lines[2]) == "1";

            // Get level theme
            line = decryptor.DecryptString(lines[3]).Split(' ');
            Theme = FindTheme(line[0]);
            wallSet = new Tileset(Game1.tileSet[(int)Theme], 32, 32, 3, 3);

            // Get room dimensions
            line = decryptor.DecryptString(lines[4]).Split(' ');
            roomWidth = int.Parse(line[0]);
            roomHeight = int.Parse(line[1]);

            // Get goal times
            // Find record
            int rec = -1;
            if (!File.Exists("Content\\records.txt"))
                File.Create("Content\\records.txt");
            StreamReader findLastLevel = new StreamReader("Content\\records.txt");
            while (!findLastLevel.EndOfStream)
            {
                string[] level = decryptor.DecryptString(findLastLevel.ReadLine()).Split(' ');
                if (level[0] == levelName && level[1] == "0")
                {
                    rec = int.Parse(level[2]);
                    break;
                }
            }
            findLastLevel.Close();
            findLastLevel.Dispose();

            // Check if record is a gold time
            bool gotGold = false;
            string findIndex = levelName.Split('_')[1];
            int ii = int.Parse(findIndex) - 1;
            string[] g = decryptor.DecryptString(Levels.levels[ii][5]).Split(' ');
            if (rec != -1 && rec < int.Parse(g[0]))
                gotGold = true;

            // If it is, unlock platinum time
            goals = new int[gotGold ? 4 : 3];
            line = decryptor.DecryptString(lines[5]).Split(' ');
            for (int i = 0; i < goals.Length; i++)
                goals[i] = int.Parse(line[i]);

            // Get objects and tiles
            int index = 6;
            while (index < lines.Length)
            {
                line = decryptor.DecryptString(lines[index]).Split(' ');
                ParseObjectOrTile(line, freeroam);
                index++;
            }
            BuildTiles();

            // Generate zipline poles
            foreach (ZipLine z in ziplines)
                z.SetPoles(this);

            // Check to see if level is already in records file. If not, add it.
            // This unlocks the level in level select, since main levels (levels hard coded into the game)
            // are added from the records file.
            bool recordFound = false;
            StreamReader reader = new StreamReader("Content\\records.txt");
            while (!reader.EndOfStream)
            {
                string s = decryptor.DecryptString(reader.ReadLine());
                if (s.Split(' ')[0] == levelName)
                {
                    record = int.Parse(s.Split(' ')[2]);
                    recordFound = true;
                    break;
                }
            }
            reader.Close();
            reader.Dispose();
            if (!recordFound)
            {
                record = -1;
                StreamWriter writer = new StreamWriter("Content\\records.txt", true);
                writer.WriteLine(decryptor.EncryptToString(levelName + " 0 -1"));
                writer.Flush();
                writer.Dispose();
            }

            UpdateViewBox(false);
        }