Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum DayOfWeek
- {
- Sunday,
- Monday,
- }
- public enum TimeOfDay
- {
- Morning,
- Evening
- // I'm not sure if I like AfterSchool being a time of day. I might keep track of whether it is a school day separate from Time of day, and keep TimeOfDay to being specific times like Evening and morning. A bool isSchoolDay should suffice for now.
- }
- public class TimeTracker
- {
- // currentDay is private, but CurrentDay is a public getter. This means you can check the variable, but not change it.
- // The same is done for currentTime.
- private DayOfWeek currentDay;
- public DayOfWeek CurrentDay => currentDay;
- private TimeOfDay currentTime;
- public TimeOfDay CurrentTime => currentTime;
- // I didn't implement a month state, but I think you can figure it out.
- // I assume holidays will be added and I think a dayOfMonth counter would be useful for that. I also think the totalDays is something that would be tracked.
- // TODO: implement where they should increment.
- private int dayOfMonth = 0;
- private int totalDays = 0;
- // Constructor used to create the class. Give it the starting day, and time.
- public TimeTracker(DayOfWeek startDay, TimeOfDay startTime)
- {
- this.currentDay = startDay;
- this.currentTime = startTime;
- }
- public void AdvanceTime()
- {
- switch (currentTime)
- {
- case TimeOfDay.Morning:
- AdvanceTimeFromMorning();
- break;
- case TimeOfDay.Evening:
- AdvanceTimeFromEvening();
- break;
- default:
- Debug.LogError("Current Time of day not defined.");
- break;
- }
- }
- private void AdvanceTimeFromMorning()
- {
- // Advance time to evening.
- currentTime = TimeOfDay.Evening;
- }
- private void AdvanceTimeFromEvening()
- {
- currentTime = TimeOfDay.Morning;
- AdvanceDay();
- }
- private void AdvanceDay()
- {
- switch (currentDay)
- {
- case DayOfWeek.Sunday:
- currentDay = DayOfWeek.Monday;
- break;
- case DayOfWeek.Monday:
- //currentDay = Tuesday that I didn't define.
- break;
- default:
- Debug.LogError("Current Time of day not defined.");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement