/Working Memory Workout/Data/SerializedPlayerData.cs
C# | 224 lines | 197 code | 15 blank | 12 comment | 22 complexity | 7f17143b8ff23ec1c52d3fe8c9766314 MD5 | raw file
Possible License(s): AGPL-1.0
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- using Microsoft.Xna.Framework.Net;
- using Microsoft.Xna.Framework.Storage;
- using Working_Memory_Workout;
- using Working_Memory_Workout.Data;
- using Working_Memory_Workout.Services;
- using Working_Memory_Workout.Entities;
- using Working_Memory_Workout.Entities.Components;
- using Working_Memory_Workout.Entities.Inputters;
- using Working_Memory_Workout.Entities.Scenes;
-
- namespace Working_Memory_Workout.Data
- {
- [Serializable]
- public class SerializedPlayerData
- {
- // SerializedPlayerData includes all serialized data.
- // It provides an open interface to its clients.
- // Currently one client is planned as an external interface for the game object's use: PlayerData
- public SerializedPlayerData() { } // Parameterless constructor needed for serialization.
-
- public SerializedPlayerData(Game1 g, string name)
- {
- Name = name;
- timeLastPlayed = DateTime.Now;
- timeFirstPlayed = DateTime.Now;
- timesPlayed = new List<double>();
- timesPlayed.Add(0);
- CreateScores(g);
- }
-
- public string Name;
- public string ActiveLevel = "1-1";
- public int ActiveStimCount
- {
- get { return Int32.Parse(ActiveLevel[0].ToString()); }
- }
- public int ActiveChunkCount
- {
- get { return Int32.Parse(ActiveLevel[2].ToString()); }
- }
- public SerializedScoreData ActiveScore { get { return GetScore(ActiveStimCount, ActiveChunkCount); } }
- public GameData ActiveGame
- {
- get
- {
- return HelperEnabled ?
- ActiveScore.GameDataB :
- ActiveScore.GameDataA;
- }
- }
- public Chunks.GameModes ActiveGameMode = Chunks.GameModes.MatchValue;
- public AdvanceModes ActiveAdvanceMode = AdvanceModes.Variable; // Set by clicking map scene scores, read by gameplay scene.
- public bool HelperEnabled = false; // toggled on/off on map screen via chunk zero clickable
- public const int PROGRESS_TO_WIN = 100;
- public int ProgressEarned = 0;
- public int ProgressUnspent = 4; // unspent progressScored, could attach events for changes to this and progress scored for map
- public double MatchChance = 0.33f;
-
- #region Advance mode stuff
- public enum AdvanceModes
- {
- Slow = 0,
- Medium = 1,
- Fast = 2,
- Variable = 3
- }
-
- // Saved time variables for fast and slow modes of play.
- private int advanceTimeSlow = 3333; // default set in constructor
- public const int SLOW_MIN = 3333; // 4 seconds minimum for "slow" mode of play.
- public const int SLOW_MAX = 600000; // 10 minutes. Why not?
- public int AdvanceTimeSlow
- {
- get { return advanceTimeSlow; }
- set { advanceTimeSlow = Math.Max(SLOW_MIN, Math.Min(SLOW_MAX, value)); } // keep in bounds
- }
- private int advanceTimeMedium = 2222; // default set in constructor
- public const int MEDIUM_MIN = 1000;
- public const int MEDIUM_MAX = 3332;
- public int AdvanceTimeMedium
- {
- get { return advanceTimeMedium; }
- set { advanceTimeMedium = Math.Max(MEDIUM_MIN, Math.Min(MEDIUM_MAX, value)); } // keep in bounds
- }
- private int advanceTimeFast = 999; // default set in constructor
- public const int FAST_MIN = 667;
- public const int FAST_MAX = 999;
- public int AdvanceTimeFast
- {
- get { return advanceTimeFast; }
- set { advanceTimeFast = Math.Max(FAST_MIN, Math.Min(FAST_MAX, value)); } // keep in bounds
- }
- public float[] beatVolumes0; // the array of floats representing the sequenced volumes for the BeatTimer class
- public float[] beatVolumes1; // the array of floats representing the sequenced volumes for the BeatTimer class
- public float[] beatVolumes2; // the array of floats representing the sequenced volumes for the BeatTimer class
- #endregion
-
-
- #region Colors
- // Some pretty colors
- public static readonly Color COLOR_CLICKABLE_DEFAULT = new Color(120, 180, 255);
- public static readonly Color COLOR_UNCLICKABLE_DEFAULT = new Color(200, 200, 200);
- public static readonly Color COLOR_HOVERED_DEFAULT = new Color(255, 140, 190);
- public static readonly Color COLOR_UNUSEABLE_DEFAULT = new Color(100, 100, 100);
- public Color ColorClickable = COLOR_CLICKABLE_DEFAULT;
- public Color ColorUnclickable = COLOR_UNCLICKABLE_DEFAULT;
- public Color ColorHovered = COLOR_HOVERED_DEFAULT;
- public Color ColorUnuseable = COLOR_UNUSEABLE_DEFAULT;
- #endregion
-
- #region Scores -- a unique SerializedScoreData object is kept for every theme/index/gameType/advanceMode combo
- public List<SerializedScoreData> scores;
-
- public SerializedScoreData GetScore(int stimCount, int chunkCount)
- {
- foreach (SerializedScoreData score in scores)
- {
- if (score.GameDataA.ChunkCount == chunkCount &&
- score.GameDataA.StimCount == stimCount)
- {
- return score;
- }
- }
- throw new NotImplementedException("unknown score: " + stimCount + ":" + chunkCount);
- }
- public void SetScore(Chunks.GameModes gameMode,
- AdvanceModes advanceMode,
- int highScore)
- {
- // Score progress, trusting whatever highScore is given
- int currentHighScore = ActiveScore.Get(gameMode, advanceMode, HelperEnabled);
- int scoreDiff = highScore - currentHighScore;
- if (currentHighScore >= 0 &&
- scoreDiff > 0 &&
- highScore > 0) // don't increase progress for negative->0, the game unlock cost
- {
- ProgressEarned += scoreDiff;
- ProgressUnspent += scoreDiff;
- }
-
- // Set the new high score, regardless of whether it's higher or lower than the old.
- ActiveScore.Set(gameMode, advanceMode, highScore, HelperEnabled);
- return;
- }
- private void CreateScores(Game1 g)
- {
- scores = new List<SerializedScoreData>();
-
- for (int i = 1; i <= 4; i++) // stimCount
- {
- for (int k = 0; k < 4; k++) // chunkCount
- {
- scores.Add(new SerializedScoreData(g, i, (int)Math.Pow(2, k)));
- }
- }
- }
- public bool IsLevelUnlocked(int stimCount, int chunkCount)
- {
- if (stimCount == 1 && chunkCount == 1)
- return true;
-
- // Get the chunk/stim counts that reflect the previous game
- // stims 1, 2, 3, 4
- // chunks 1, 2, 4, 8
- if (chunkCount == 1)
- {
- stimCount--;
- chunkCount = 8;
- }
- else if (chunkCount == 2)
- chunkCount = 1;
- else if (chunkCount == 4)
- chunkCount = 2;
- else if (chunkCount == 8)
- chunkCount = 4;
-
- // We now have the stimCount/chunkCount for the previous game
- SerializedScoreData prevScore = GetScore(stimCount, chunkCount);
- return prevScore.GetHighestScore() > 0;
- }
- #endregion
-
- #region time spent playing
- // Stats of time spent playing.
- public double timePlayedTotal;
- public double timePlayedToday;
- public DateTime timeLastPlayed;
- public DateTime timeFirstPlayed;
- public int minsToWin = -1;
- public List<double> timesPlayed;
- #endregion
-
- #region options
- public bool oMoveStimuli = true;
- public bool oScaleStimuli = true;
- public bool oDisableAudio = false;
- public bool oDisableImages = false;
- public bool oDisableText = false;
- public bool oFocusEnabled = true;
- public bool oNBackMode = false;
- public int oCorrectSound = 60;
- public int oIncorrectSound = 60;
- public bool oCorrectImage = true;
- public bool oIncorrectImage = true;
- public int oBeatPitch = 40;
- public int oBeatVolume = 60;
- public bool oBounceColors = true;
- public int oAudioPitch = 50; // 0 = -1.0f, 50 = 0.0f, 100 = 1.0f pitch playing
- public int oAudioVolume = 100;
- public bool oPauseOnLevel = true;
- public int oFadeDelay = 0;
- #endregion
- }
- }