Advertisement
Guest User

Time

a guest
Dec 23rd, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. //---------------------------
  2. // Includes
  3. //---------------------------
  4. #include "Time.h"
  5.  
  6. //---------------------------
  7. // Defines
  8. //---------------------------
  9. #define GAME_ENGINE (GameEngine::GetSingleton())
  10.  
  11. //---------------------------
  12. // Constructor & Destructor
  13. //---------------------------
  14. Time::Time(int hour , int minute , int second):m_Hour(59),m_Minute(59),m_Second(59)
  15. {
  16.     // nothing to create
  17. }
  18.  
  19. Time::~Time()
  20. {
  21.     // nothing to destroy
  22. }
  23.  
  24. //---------------------------
  25. // Methods
  26. //---------------------------
  27.  
  28. // Add here the methods
  29.  
  30. void Time::NextHour()
  31. {
  32.     if(m_Hour<24)
  33.     {
  34.     ++m_Hour;
  35.     }
  36.     else
  37.     {
  38.         m_Hour=0;
  39.     }
  40. }
  41. void Time::NextMinute()
  42. {
  43.     if(m_Minute<60)
  44.     {
  45.     ++m_Minute;
  46.     }
  47.     else
  48.     {
  49.         m_Minute=0;
  50.     }
  51. }
  52. void Time::NextSecond()
  53. {
  54.     if(m_Second<60)
  55.     {
  56.     ++m_Second;
  57.     }
  58.     else
  59.     {
  60.         m_Second=0;
  61.     }
  62. }
  63. string Time::ToString()
  64. {
  65.     string hourstring,minutestring,secondstring;
  66.     if (m_Hour<10)
  67.     {
  68.          hourstring=("0")+m_Hour;
  69.     }
  70.     else
  71.     {
  72.         hourstring=m_Hour;
  73.     }
  74.     if (m_Minute<10)
  75.     {
  76.          minutestring=("0")+m_Minute;
  77.     }
  78.     else
  79.     {
  80.         minutestring=m_Minute;
  81.     }
  82.     if (m_Second<10)
  83.     {
  84.          secondstring=("0")+m_Second;
  85.     }
  86.     else
  87.     {
  88.         secondstring=m_Second;
  89.     }
  90.  
  91.     return string()+hourstring+(':')+minutestring+(':')+secondstring;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement