Esempio n. 1
0
 public static void AddTakenCoins(LevelID lid, IEnumerable <int> indices)
 {
     lock (staticMutationLock) {
         LevelCompletionDetails oldDetails = GetDetails(lid);
         foreach (var index in indices)
         {
             if (oldDetails.CoinIndicesCollected.Contains(index))
             {
                 throw new ApplicationException("Error: Can not add coin index '" + index + "' twice.");
             }
         }
         int[] newIndicesArr = new int[oldDetails.CoinIndicesCollected.Count() + indices.Count()];
         for (int i = 0; i < newIndicesArr.Length; ++i)
         {
             if (i < oldDetails.CoinIndicesCollected.Count())
             {
                 newIndicesArr[i] = oldDetails.CoinIndicesCollected.ElementAt(i);
             }
             else
             {
                 newIndicesArr[i] = indices.ElementAt(i - oldDetails.CoinIndicesCollected.Count());
             }
         }
         LevelCompletionDetails newDetails = new LevelCompletionDetails(
             oldDetails.GoldenEggClaimed,
             oldDetails.BestTimeRemainingMs,
             newIndicesArr
             );
         SetDetails(lid, newDetails);
         RecalculateSecondHandState();
     }
 }
Esempio n. 2
0
 public static void LoadAllMetadata()
 {
     lock (staticMutationLock) {
         for (int worldIndex = 0; worldIndex < 11; ++worldIndex)
         {
             for (int levelIndex = 0; levelIndex < 10; ++levelIndex)
             {
                 LevelID lid      = new LevelID((byte)worldIndex, (byte)levelIndex);
                 string  filename = String.Empty;
                 if (LevelExists(lid))
                 {
                     filename = Path.Combine(AssetLocator.LevelsDir, GetLevelFileName(lid));
                 }
                 if (filename == String.Empty || !File.Exists(filename))
                 {
                     StringBuilder randomStringBuilder = new StringBuilder();
                     int           strLen = RandomProvider.Next(3, 16);
                     for (int c = 0; c < strLen; ++c)
                     {
                         char x = (char)RandomProvider.Next(65, 92);
                         if (x == (char)91)
                         {
                             x = ' ';
                         }
                         randomStringBuilder.Append(x);
                     }
                     var maxTime    = 30000 + RandomProvider.Next(1, 5) * 15000;
                     var bronzeTime = maxTime - RandomProvider.Next(1, 4) * 2500;
                     var silverTime = bronzeTime - RandomProvider.Next(1, 4) * 2500;
                     var goldTime   = silverTime - RandomProvider.Next(1, 4) * 2500;
                     loadedMetadata[worldIndex * 10 + levelIndex] = new LevelMetadata(
                         randomStringBuilder.ToString(),
                         maxTime,
                         bronzeTime,
                         silverTime,
                         goldTime,
                         RandomProvider.Next(1, 51)
                         );
                 }
                 else
                 {
                     var levelDesc = (GameLevelDescription)LevelDescription.Load(filename, false);
                     loadedMetadata[worldIndex * 10 + levelIndex] = new LevelMetadata(
                         levelDesc.Title,
                         levelDesc.LevelTimerMaxMs,
                         levelDesc.LevelTimerBronzeMs,
                         levelDesc.LevelTimerSilverMs,
                         levelDesc.LevelTimerGoldMs,
                         levelDesc.GetGameObjectsByType <LizardCoin>().Count()
                         );
                     levelDesc.Dispose();
                 }
                 var coinsInLevel = loadedMetadata[worldIndex * 10 + levelIndex].TotalCoinsInLevel;
                 totalCoinsInGame += coinsInLevel;
                 totalCoinsPerWorld[worldIndex] += coinsInLevel;
             }
         }
     }
 }
Esempio n. 3
0
        private static void RecalculateSecondHandState()
        {
            totalTakenCoins  = 0;
            totalGoldenEggs  = 0;
            totalGoldStars   = 0;
            totalSilverStars = 0;
            totalBronzeStars = 0;
            for (int w = 0; w < 11; ++w)
            {
                for (int l = 0; l < 10; ++l)
                {
                    var lcd = GetDetails(w, l);
                    totalTakenCoins += lcd.CoinIndicesCollected.Count();
                    if (lcd.GoldenEggClaimed)
                    {
                        ++totalGoldenEggs;
                    }
                    if (lcd.BestTimeRemainingMs.HasValue)
                    {
                        LevelID lid = new LevelID((byte)w, (byte)l);
                        if (lcd.BestTimeRemainingMs >= LevelDatabase.GetLevelGoldTime(lid))
                        {
                            stars[w * 10 + l] = Star.Gold;
                        }
                        else if (lcd.BestTimeRemainingMs >= LevelDatabase.GetLevelSilverTime(lid))
                        {
                            stars[w * 10 + l] = Star.Silver;
                        }
                        else if (lcd.BestTimeRemainingMs >= LevelDatabase.GetLevelBronzeTime(lid))
                        {
                            stars[w * 10 + l] = Star.Bronze;
                        }
                        else
                        {
                            stars[w * 10 + l] = Star.None;
                        }

                        switch (stars[w * 10 + l])
                        {
                        case Star.Gold:
                            ++totalGoldStars;
                            goto case Star.Silver;

                        case Star.Silver:
                            ++totalSilverStars;
                            goto case Star.Bronze;

                        case Star.Bronze:
                            ++totalBronzeStars;
                            break;
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 public static void AddGoldenEgg(LevelID lid)
 {
     lock (staticMutationLock) {
         var oldDetails = GetDetails(lid);
         if (oldDetails.GoldenEggClaimed)
         {
             throw new ApplicationException("Golden egg already claimed for level.");
         }
         SetDetails(lid, new LevelCompletionDetails(true, oldDetails.BestTimeRemainingMs, oldDetails.CoinIndicesCollected.ToArray()));
         RecalculateSecondHandState();
     }
 }
Esempio n. 5
0
        public static void SetBestTimeForLevel(LevelID lid, int timeRemainingMs)
        {
            lock (staticMutationLock) {
                var oldDetails = GetDetails(lid);
                if (oldDetails.BestTimeRemainingMs != null && timeRemainingMs <= oldDetails.BestTimeRemainingMs)
                {
                    throw new ApplicationException("New time is not better than previous.");
                }

                SetDetails(lid, new LevelCompletionDetails(oldDetails.GoldenEggClaimed, timeRemainingMs, oldDetails.CoinIndicesCollected.ToArray()));
                RecalculateSecondHandState();
            }
        }
Esempio n. 6
0
        public static bool ShouldDisplayTutorial(LevelID lid)
        {
            if (lid.WorldIndex != 0)
            {
                return(false);
            }
            if (GetTutorialText(lid.LevelIndex) == String.Empty)
            {
                return(false);
            }
            if (PersistedWorldData.GetBestTimeForLevel(lid) != null)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
        public static void LoadLevel(LevelID levelID)
        {
            lock (staticMutationLock) {
                UnloadCurrentlyLoaded();

                string filename = Path.Combine("Previews\\", "level" + levelID.WorldIndex + "-" + levelID.LevelIndex + ".png");
                if (!File.Exists(Path.Combine(AssetLocator.MaterialsDir, filename)))
                {
                    loadedTextures.Add(new KeyValuePair <ITexture2D, string>(
                                           AssetLocator.LoadTexture("blue.bmp", false),
                                           "blue.bmp"
                                           ));
                }
                else
                {
                    loadedTextures.Add(new KeyValuePair <ITexture2D, string>(
                                           AssetLocator.LoadTexture(filename, false),
                                           filename
                                           ));
                }

                curTexIndex = 0;
            }
        }
Esempio n. 8
0
 public static string GetLevelMaxTimeAsString(LevelID lid)
 {
     return(MakeTimeString(GetLevelMaxTime(lid)));
 }
Esempio n. 9
0
 public static Star GetStarForLevel(LevelID lid)
 {
     lock (staticMutationLock) {
         return(stars[lid.WorldIndex * 10 + lid.LevelIndex]);
     }
 }
Esempio n. 10
0
 public static bool GoldenEggTakenForLevel(LevelID lid)
 {
     lock (staticMutationLock) {
         return(GetDetails(lid).GoldenEggClaimed);
     }
 }
Esempio n. 11
0
 public static string GetLevelFileName(LevelID levelID)
 {
     return(filenameMap[levelID.WorldIndex][levelID.LevelIndex].Key + ".ell");
 }
Esempio n. 12
0
 public static IEnumerable <int> GetTakenCoinIndices(LevelID lid)
 {
     lock (staticMutationLock) {
         return(GetDetails(lid).CoinIndicesCollected);
     }
 }
Esempio n. 13
0
 public static bool LevelExists(LevelID levelID)
 {
     return(filenameMap.Length > levelID.WorldIndex && filenameMap[levelID.WorldIndex].Length > levelID.LevelIndex);
 }
Esempio n. 14
0
 public static int?GetBestTimeForLevel(LevelID lid)
 {
     lock (staticMutationLock) {
         return(GetDetails(lid).BestTimeRemainingMs);
     }
 }
Esempio n. 15
0
 private static LevelCompletionDetails GetDetails(LevelID lid)
 {
     return(GetDetails(lid.WorldIndex, lid.LevelIndex));
 }
Esempio n. 16
0
 private static void SetDetails(LevelID lid, LevelCompletionDetails details)
 {
     SetDetails(lid.WorldIndex, lid.LevelIndex, details);
 }
Esempio n. 17
0
 internal LevelFilePair(LevelID levelId, string skyboxFileName, string levelFileName)
 {
     LevelID        = levelId;
     SkyboxFileName = skyboxFileName;
     LevelFileName  = levelFileName;
 }
Esempio n. 18
0
 public static int GetLevelTotalCoins(LevelID lid)
 {
     lock (staticMutationLock) {
         return(loadedMetadata[lid.WorldIndex * 10 + lid.LevelIndex].TotalCoinsInLevel);
     }
 }
Esempio n. 19
0
 public static int GetLevelMaxTime(LevelID lid)
 {
     lock (staticMutationLock) {
         return(loadedMetadata[lid.WorldIndex * 10 + lid.LevelIndex].MaxStarTimeMs);
     }
 }
Esempio n. 20
0
 public static LevelDifficulty GetLevelDifficulty(LevelID lid)
 {
     lock (staticMutationLock) {
         return(filenameMap[lid.WorldIndex][lid.LevelIndex].Value);
     }
 }
Esempio n. 21
0
 public static string GetLevelTitle(LevelID lid)
 {
     lock (staticMutationLock) {
         return(loadedMetadata[lid.WorldIndex * 10 + lid.LevelIndex].Title);
     }
 }