PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11. using Microsoft.Xna.Framework.Net;
  12. using Microsoft.Xna.Framework.Storage;
  13. using Working_Memory_Workout;
  14. using Working_Memory_Workout.Data;
  15. using Working_Memory_Workout.Services;
  16. using Working_Memory_Workout.Entities;
  17. using Working_Memory_Workout.Entities.Components;
  18. using Working_Memory_Workout.Entities.Inputters;
  19. using Working_Memory_Workout.Entities.Scenes;
  20. namespace Working_Memory_Workout.Data
  21. {
  22. [Serializable]
  23. public class SerializedPlayerData
  24. {
  25. // SerializedPlayerData includes all serialized data.
  26. // It provides an open interface to its clients.
  27. // Currently one client is planned as an external interface for the game object's use: PlayerData
  28. public SerializedPlayerData() { } // Parameterless constructor needed for serialization.
  29. public SerializedPlayerData(Game1 g, string name)
  30. {
  31. Name = name;
  32. timeLastPlayed = DateTime.Now;
  33. timeFirstPlayed = DateTime.Now;
  34. timesPlayed = new List<double>();
  35. timesPlayed.Add(0);
  36. CreateScores(g);
  37. }
  38. public string Name;
  39. public string ActiveLevel = "1-1";
  40. public int ActiveStimCount
  41. {
  42. get { return Int32.Parse(ActiveLevel[0].ToString()); }
  43. }
  44. public int ActiveChunkCount
  45. {
  46. get { return Int32.Parse(ActiveLevel[2].ToString()); }
  47. }
  48. public SerializedScoreData ActiveScore { get { return GetScore(ActiveStimCount, ActiveChunkCount); } }
  49. public GameData ActiveGame
  50. {
  51. get
  52. {
  53. return HelperEnabled ?
  54. ActiveScore.GameDataB :
  55. ActiveScore.GameDataA;
  56. }
  57. }
  58. public Chunks.GameModes ActiveGameMode = Chunks.GameModes.MatchValue;
  59. public AdvanceModes ActiveAdvanceMode = AdvanceModes.Variable; // Set by clicking map scene scores, read by gameplay scene.
  60. public bool HelperEnabled = false; // toggled on/off on map screen via chunk zero clickable
  61. public const int PROGRESS_TO_WIN = 100;
  62. public int ProgressEarned = 0;
  63. public int ProgressUnspent = 4; // unspent progressScored, could attach events for changes to this and progress scored for map
  64. public double MatchChance = 0.33f;
  65. #region Advance mode stuff
  66. public enum AdvanceModes
  67. {
  68. Slow = 0,
  69. Medium = 1,
  70. Fast = 2,
  71. Variable = 3
  72. }
  73. // Saved time variables for fast and slow modes of play.
  74. private int advanceTimeSlow = 3333; // default set in constructor
  75. public const int SLOW_MIN = 3333; // 4 seconds minimum for "slow" mode of play.
  76. public const int SLOW_MAX = 600000; // 10 minutes. Why not?
  77. public int AdvanceTimeSlow
  78. {
  79. get { return advanceTimeSlow; }
  80. set { advanceTimeSlow = Math.Max(SLOW_MIN, Math.Min(SLOW_MAX, value)); } // keep in bounds
  81. }
  82. private int advanceTimeMedium = 2222; // default set in constructor
  83. public const int MEDIUM_MIN = 1000;
  84. public const int MEDIUM_MAX = 3332;
  85. public int AdvanceTimeMedium
  86. {
  87. get { return advanceTimeMedium; }
  88. set { advanceTimeMedium = Math.Max(MEDIUM_MIN, Math.Min(MEDIUM_MAX, value)); } // keep in bounds
  89. }
  90. private int advanceTimeFast = 999; // default set in constructor
  91. public const int FAST_MIN = 667;
  92. public const int FAST_MAX = 999;
  93. public int AdvanceTimeFast
  94. {
  95. get { return advanceTimeFast; }
  96. set { advanceTimeFast = Math.Max(FAST_MIN, Math.Min(FAST_MAX, value)); } // keep in bounds
  97. }
  98. public float[] beatVolumes0; // the array of floats representing the sequenced volumes for the BeatTimer class
  99. public float[] beatVolumes1; // the array of floats representing the sequenced volumes for the BeatTimer class
  100. public float[] beatVolumes2; // the array of floats representing the sequenced volumes for the BeatTimer class
  101. #endregion
  102. #region Colors
  103. // Some pretty colors
  104. public static readonly Color COLOR_CLICKABLE_DEFAULT = new Color(120, 180, 255);
  105. public static readonly Color COLOR_UNCLICKABLE_DEFAULT = new Color(200, 200, 200);
  106. public static readonly Color COLOR_HOVERED_DEFAULT = new Color(255, 140, 190);
  107. public static readonly Color COLOR_UNUSEABLE_DEFAULT = new Color(100, 100, 100);
  108. public Color ColorClickable = COLOR_CLICKABLE_DEFAULT;
  109. public Color ColorUnclickable = COLOR_UNCLICKABLE_DEFAULT;
  110. public Color ColorHovered = COLOR_HOVERED_DEFAULT;
  111. public Color ColorUnuseable = COLOR_UNUSEABLE_DEFAULT;
  112. #endregion
  113. #region Scores -- a unique SerializedScoreData object is kept for every theme/index/gameType/advanceMode combo
  114. public List<SerializedScoreData> scores;
  115. public SerializedScoreData GetScore(int stimCount, int chunkCount)
  116. {
  117. foreach (SerializedScoreData score in scores)
  118. {
  119. if (score.GameDataA.ChunkCount == chunkCount &&
  120. score.GameDataA.StimCount == stimCount)
  121. {
  122. return score;
  123. }
  124. }
  125. throw new NotImplementedException("unknown score: " + stimCount + ":" + chunkCount);
  126. }
  127. public void SetScore(Chunks.GameModes gameMode,
  128. AdvanceModes advanceMode,
  129. int highScore)
  130. {
  131. // Score progress, trusting whatever highScore is given
  132. int currentHighScore = ActiveScore.Get(gameMode, advanceMode, HelperEnabled);
  133. int scoreDiff = highScore - currentHighScore;
  134. if (currentHighScore >= 0 &&
  135. scoreDiff > 0 &&
  136. highScore > 0) // don't increase progress for negative->0, the game unlock cost
  137. {
  138. ProgressEarned += scoreDiff;
  139. ProgressUnspent += scoreDiff;
  140. }
  141. // Set the new high score, regardless of whether it's higher or lower than the old.
  142. ActiveScore.Set(gameMode, advanceMode, highScore, HelperEnabled);
  143. return;
  144. }
  145. private void CreateScores(Game1 g)
  146. {
  147. scores = new List<SerializedScoreData>();
  148. for (int i = 1; i <= 4; i++) // stimCount
  149. {
  150. for (int k = 0; k < 4; k++) // chunkCount
  151. {
  152. scores.Add(new SerializedScoreData(g, i, (int)Math.Pow(2, k)));
  153. }
  154. }
  155. }
  156. public bool IsLevelUnlocked(int stimCount, int chunkCount)
  157. {
  158. if (stimCount == 1 && chunkCount == 1)
  159. return true;
  160. // Get the chunk/stim counts that reflect the previous game
  161. // stims 1, 2, 3, 4
  162. // chunks 1, 2, 4, 8
  163. if (chunkCount == 1)
  164. {
  165. stimCount--;
  166. chunkCount = 8;
  167. }
  168. else if (chunkCount == 2)
  169. chunkCount = 1;
  170. else if (chunkCount == 4)
  171. chunkCount = 2;
  172. else if (chunkCount == 8)
  173. chunkCount = 4;
  174. // We now have the stimCount/chunkCount for the previous game
  175. SerializedScoreData prevScore = GetScore(stimCount, chunkCount);
  176. return prevScore.GetHighestScore() > 0;
  177. }
  178. #endregion
  179. #region time spent playing
  180. // Stats of time spent playing.
  181. public double timePlayedTotal;
  182. public double timePlayedToday;
  183. public DateTime timeLastPlayed;
  184. public DateTime timeFirstPlayed;
  185. public int minsToWin = -1;
  186. public List<double> timesPlayed;
  187. #endregion
  188. #region options
  189. public bool oMoveStimuli = true;
  190. public bool oScaleStimuli = true;
  191. public bool oDisableAudio = false;
  192. public bool oDisableImages = false;
  193. public bool oDisableText = false;
  194. public bool oFocusEnabled = true;
  195. public bool oNBackMode = false;
  196. public int oCorrectSound = 60;
  197. public int oIncorrectSound = 60;
  198. public bool oCorrectImage = true;
  199. public bool oIncorrectImage = true;
  200. public int oBeatPitch = 40;
  201. public int oBeatVolume = 60;
  202. public bool oBounceColors = true;
  203. public int oAudioPitch = 50; // 0 = -1.0f, 50 = 0.0f, 100 = 1.0f pitch playing
  204. public int oAudioVolume = 100;
  205. public bool oPauseOnLevel = true;
  206. public int oFadeDelay = 0;
  207. #endregion
  208. }
  209. }