Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stage1PlayerSaved.health = 80;
- stage1PlayerSaved.position = 50.3f;
- stage1PlayerSaved.color = Color.Green;
- public class Player
- {
- public int PId; //This will not change
- public string Name; //This will not change
- public int Energy; //This may change over stanges
- //you should have a method which returns PlayerInfo object
- public PlayerInfo GetPlayerInfoToBeStored()
- {
- return new PlayerInfo(this.Energy);
- }
- }
- //this class will have only those information which can change
- public class PlayerInfo
- {
- public int Energy;
- public PlayerInfo(int playerEnergey)
- {
- Energy = playerEnergey;
- }
- }
- public Dictionary<int, Dictionary<int, PlayerInfo>> StoredPlayerState =
- new Dictionary<int, Dictionary<int, PlayerInfo>>();
- public void SavePlayerInfo(int stageNum, List<Player> playerList)
- {
- Dictionary<int, PlayerInfo> playerInfoTable = new Dictionary<int, PlayerInfo>();
- foreach(Player player in playerList)
- {
- playerInfoTable.Add( player.PId, player.GetPlayerInfoToBeStored());
- StoredPlayerState.Add(stageNum, playerInfoTable);
- }
- }
- public void MainMethod()
- {
- List<Player> playerList = new List<Player>();
- //add players in this list
- //after stage 1
- SavePlayerInfo(1, playerList);
- //after stage 2
- SavePlayerInfo(2, playerList);
- }
- public sealed class GameVariables
- {
- private static readonly _instance = new GameVariables();
- public static GameVariables Intance { get { return _instance; } }
- private GameVariables()
- {
- Reset();
- }
- public void Reset()
- {
- //Initialize your variables here when you start a new game
- PlayerHealth = 100;
- PlayerPosition = 0f;
- [...]
- }
- public int PlayerHealth { get; set; }
- public float PlayerPosition { get; set; }
- [...]
- }
- public class SomeScene
- {
- void update()
- {
- GameVariables.Instance.PlayerHealth = 80;
- }
- }
Add Comment
Please, Sign In to add comment