Due to the importance of this project, one of the primary objectives of using an Agile methodology is to identify and address critical aspects of the system early in the development process. Since the project's goal is to create a virtual pet, it is essential that users are able to care for their creature on a daily basis. To support this functionality, one of the initial features implemented was a system to track the passage of real-world time and persist relevant timestamps in a non-volatile database.
Thanks to my prior work experience, I have frequently worked with timestamps and time-based logic. This allowed me to transfer those skills to this project by implementing UNIX timestamps, a format that represents the number of seconds elapsed since the Unix Epoch (January 1st, 1970 at UTC). Using this format helps avoid ambiguities commonly associated with other timestamp formats, such as time zone differences or date formatting. Additionally, it makes it straightforward to determine whether the current time has passed a saved timestamp or whether a new day has begun.
public long getUnixTimeOfWaitingTime(long baseUnixTimestamp,WaitingTime waitTime)
{
DateTime baseTime = DateTimeOffset.FromUnixTimeSeconds(baseUnixTimestamp).UtcDateTime;
TimeSpan waitDuration = waitTime switch
{
WaitingTime.none => TimeSpan.Zero,
WaitingTime.gamePlayTime => TimeSpan.FromMinutes(15),
WaitingTime.day => TimeSpan.FromDays(1),
WaitingTime.week => TimeSpan.FromDays(7),
WaitingTime.twoWeeks => TimeSpan.FromDays(14),
WaitingTime.threeWeeks => TimeSpan.FromDays(21),
WaitingTime.month => TimeSpan.FromDays(30),
_ => TimeSpan.Zero
};
DateTime resultTime = baseTime.Add(waitDuration);
return ((DateTimeOffset)resultTime).ToUnixTimeSeconds();
}
public bool isDifferentDayFromNow(long unixTimestamp)
{
DateTime inputDateUtc = DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).UtcDateTime;
DateTime inputDateLocal = inputDateUtc.ToLocalTime();
DateTime nowLocal = DateTime.Now;
return inputDateLocal.Date != nowLocal.Date;
}
Once the initial logic for handling timestamps was implemented, the next step was to store this data in an encrypted database. Although the logic may evolve as gameplay features are developed, the core structure of the relevant classes has already been established and tested.
On another note, progress has also been made in acquiring materials and hardware to build the initial prototype of the hologram machine. The 3D printing of structural components has now begun.
