Guest User

Untitled

a guest
Jun 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. stage1PlayerSaved.health = 80;
  2. stage1PlayerSaved.position = 50.3f;
  3. stage1PlayerSaved.color = Color.Green;
  4.  
  5. public class Player
  6. {
  7. public int PId; //This will not change
  8. public string Name; //This will not change
  9. public int Energy; //This may change over stanges
  10.  
  11. //you should have a method which returns PlayerInfo object
  12. public PlayerInfo GetPlayerInfoToBeStored()
  13. {
  14. return new PlayerInfo(this.Energy);
  15. }
  16. }
  17.  
  18. //this class will have only those information which can change
  19. public class PlayerInfo
  20. {
  21. public int Energy;
  22.  
  23. public PlayerInfo(int playerEnergey)
  24. {
  25. Energy = playerEnergey;
  26. }
  27. }
  28.  
  29. public Dictionary<int, Dictionary<int, PlayerInfo>> StoredPlayerState =
  30. new Dictionary<int, Dictionary<int, PlayerInfo>>();
  31.  
  32. public void SavePlayerInfo(int stageNum, List<Player> playerList)
  33. {
  34. Dictionary<int, PlayerInfo> playerInfoTable = new Dictionary<int, PlayerInfo>();
  35. foreach(Player player in playerList)
  36. {
  37. playerInfoTable.Add( player.PId, player.GetPlayerInfoToBeStored());
  38. StoredPlayerState.Add(stageNum, playerInfoTable);
  39. }
  40. }
  41.  
  42. public void MainMethod()
  43. {
  44. List<Player> playerList = new List<Player>();
  45. //add players in this list
  46.  
  47. //after stage 1
  48. SavePlayerInfo(1, playerList);
  49.  
  50. //after stage 2
  51. SavePlayerInfo(2, playerList);
  52. }
  53.  
  54. public sealed class GameVariables
  55. {
  56. private static readonly _instance = new GameVariables();
  57.  
  58. public static GameVariables Intance { get { return _instance; } }
  59.  
  60. private GameVariables()
  61. {
  62. Reset();
  63. }
  64.  
  65. public void Reset()
  66. {
  67. //Initialize your variables here when you start a new game
  68. PlayerHealth = 100;
  69. PlayerPosition = 0f;
  70.  
  71. [...]
  72. }
  73.  
  74. public int PlayerHealth { get; set; }
  75. public float PlayerPosition { get; set; }
  76.  
  77. [...]
  78. }
  79.  
  80. public class SomeScene
  81. {
  82. void update()
  83. {
  84. GameVariables.Instance.PlayerHealth = 80;
  85. }
  86. }
Add Comment
Please, Sign In to add comment