private bool DetermineIsUnlocked() { if (this.GameRoom == GameRooms.Level1) { return(true); } var previous_level_game_room = this.GameRoom - 1; int required_score = Settings.LevelScoreRequirements[(int)previous_level_game_room]; int highest_score = 0; var speeds = new [] { GameplaySpeeds.Slow, GameplaySpeeds.Medium, GameplaySpeeds.Fast }; foreach (var speed in speeds) { string save_file_path = Settings.GetSaveFilePath(previous_level_game_room, speed); string data = SaveDataHandler.LoadData(save_file_path); int score = 0; bool success = (data != null && int.TryParse(data, out score)); if (success && score > highest_score) { highest_score = score; } } return(highest_score >= required_score); }
public static void PostStats(bool force_post = false) { #if XBOX_LIVE if (StatTracker.FoodEaten > 0) { XboxLiveStatsManager.SetStatInteger(XboxLiveStats.FoodEaten, StatTracker.FoodEaten); } var game_rooms = Enum.GetValues(typeof(GameRooms)); var game_speeds = Enum.GetValues(typeof(GameplaySpeeds)); foreach (GameRooms game_room in game_rooms) { foreach (GameplaySpeeds gameplay_speed in game_speeds) { const string prefix = "LongestSnake"; string stat_string = prefix + game_room + gameplay_speed; bool success = Enum.TryParse(typeof(XboxLiveStats), stat_string, out var stat); if (success && stat is XboxLiveStats) { string data = SaveDataHandler.LoadData(Settings.GetSaveFilePath(game_room, gameplay_speed)); int.TryParse(data, out int score); if (score > 0) { XboxLiveStatsManager.SetStatInteger((XboxLiveStats)stat, score); } } } } XboxLiveStatsManager.CheckAndFlush(force_post); #else #endif }
public static void Load() { StatTracker.Reset(); string data_string = SaveDataHandler.LoadData(Settings.StatTrackerSavePath); if (data_string != null) { StatTracker.FoodEaten = int.Parse(data_string); } }
public Scoreboard() { this.Depth = -100; this.Position = new Vector2(Engine.Game.CanvasWidth / 2 - Scoreboard.Width / 2, 30 + 30 + 20); this.BackgroundRegion = new Region(ContentHolder.Get(Settings.CurrentBackground), (int)this.Position.X, (int)this.Position.Y, Scoreboard.Width, Scoreboard.Height, 0, 0); this.SnakeRegion = new Region(ContentHolder.Get(Settings.CurrentSnake)); string data = SaveDataHandler.LoadData(Settings.CurrentSaveFilePath); bool success = (data != null && int.TryParse(data, out this.HighScore)); if (!success) { this.SaveHighscore(); } }
public override void onSwitchTo(Room previous_room, Dictionary <string, object> args) { Engine.SpawnInstance <LoadingSplash>(); var timer = new GameTimeSpan(); Action initialize = () => { #if ADS #if ANDROID #if AMAZON Engine.SpawnInstance <AmazonUpgrade>(); #endif #endif #endif #if XBOX_LIVE // Wait for Xbox Live login to complete if attempting const int xbox_live_timeout = 5000; while (XboxLiveObject.CurrentlyAttemptingSignIn && timer.TotalMilliseconds <= xbox_live_timeout) { System.Threading.Thread.Sleep(10); } #endif // Load all game data to initialize the SaveDataHandler cache Debug.WriteLine("########### Loading Save Files In To Cache ##########"); foreach (GameRooms game_room in Enum.GetValues(typeof(GameRooms))) { foreach (GameplaySpeeds gameplay_speed in Enum.GetValues(typeof(GameplaySpeeds))) { string data = SaveDataHandler.LoadData(Settings.GetSaveFilePath(game_room, gameplay_speed)); Debug.WriteLine(game_room + " - " + gameplay_speed + ": " + data); } } Debug.WriteLine("########### Loading Save Files In To Cache ##########"); // Wait until initial data loading occurs to spawn persistent stat tracker entity Engine.SpawnInstance <StatTracker>(); // Preload in game assemblies for (int i = 0; i < this.AssembliesToPreload.Length; i++) { try { System.Reflection.Assembly.Load(this.AssembliesToPreload[i]); } catch { Debug.WriteLine("Unable to preload: " + this.AssembliesToPreload[i]); } } // If time remains after doing these operations set the time to allow splash screen to remain int remaining_time_to_wait = RoomInit.MinimumSplashDuration - (int)timer.TotalMilliseconds; if (remaining_time_to_wait < 0) { remaining_time_to_wait = 0; } // Setup switching to RoomMain after timeout Engine.SpawnInstance(new TimedExecution(remaining_time_to_wait, () => Engine.ChangeRoom <RoomMain>())); }; Engine.SpawnInstance(new TimedExecution(500, initialize)); }