Question

I am working on a small personal game/project (RPG), and I want the ability to denote how many days are in a year, etc.

At first, I thought that DateTime and TimeSpan objects would be perfect for my uses, but they appear to be fixed in a 365 day Gregorian Calendar. In a fantasy game, it wouldn't be unusual for a world to have a longer/shorter year (many systems use an "ideal" 360 days, for example).

What are my options for implementation? Is there actually a way to configure these structs to my needs, or should I implement my own methods and classes to deal with this?

Était-ce utile?

La solution

I think you should move for your own method no need of struct, little bit conversion will be required and method will solve the problem hopefully efficiently

Autres conseils

Look into NodaTime, it has a CalendarSystem concept that might suit your needs.

http://nodatime.org/1.2.x/userguide/concepts.html

What you want to do is called "day count convention". It's not really hard to implement, and this article can really help you to do it: http://en.wikipedia.org/wiki/Day_count_convention

DateTime is always Gregorian with its numeric fields, but can use a different calendar when parsing or outputting strings. See this article for working with other calendars in .NET.

There are many built in, or you could consider writing your own custom calendar, by extending System.Globalization.Calendar.

TimeSpan on the other hand isn't for calendars or dates at all. It is for elapsed time. It's "day" is simply a 24 hour period, not related to any particular calendar.

Zeeshan is probably correct that you usually don't need to do this. But I supposed that it depends on how complex your game is.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top