using System; using System.Diagnostics; namespace SpaceInvaders { public class GlobalTimer { //------------------------------------------------------------------- // FIELDS //------------------------------------------------------------------- protected float currGlobalTime; private static GlobalTimer poInstance = null; //------------------------------------------------------------------- // PRIVATE CONSTRUCTION //------------------------------------------------------------------- private GlobalTimer() { this.currGlobalTime = 0.0f; } //------------------------------------------------------------------- // PUBLIC METHODS //------------------------------------------------------------------- public static void Update(float time) { GlobalTimer pTimer = GlobalTimer.GetInstance(); pTimer.currGlobalTime = time; } public static float GetTime() { GlobalTimer pTimer = GlobalTimer.GetInstance(); return pTimer.currGlobalTime; } //------------------------------------------------------------------- // PRIVATE METHODS //------------------------------------------------------------------- private static GlobalTimer GetInstance() { if (GlobalTimer.poInstance == null) { GlobalTimer.poInstance = new GlobalTimer(); Debug.Assert(GlobalTimer.poInstance != null); } return GlobalTimer.poInstance; } } //end class } // end namespace