using System; namespace Model { /// /// a Turn consists of a Player, a DateTime, and a IEnumerable of AbstractDieFace /// Like a turn in some game. ///
/// Two turns are equal if they are litterally the same instance in RAM /// (default behaviors Equals() and GetHashCode()) ///
public class Turn { /// /// the date and time, adjusted to UTC /// public readonly DateTime when; /// /// the Player who rolled the dice /// public readonly Player player; /* public IEnumerable Faces { get; private set; } */ /// /// this private constructor is to be used only by factories /// /// date and time of the turn /// player who played the turn // TODO add faces private Turn(DateTime when, Player player/*, IEnumerable faces*/) { this.when = when; this.player = player; /*Faces = faces;*/ } /// /// creates a Turn with a specified time, passed as a parameter. ///
/// whatever the DateTimeKind of might be, /// it will become UTC during construction ///
/// date and time of the turn /// player who played the turn /// a new Turn object // TODO add faces public static Turn CreateWithSpecifiedTime(DateTime when, Player player/*, IEnumerable faces*/) { // TODO add validation for faces too if (player == null) { throw new ArgumentNullException(nameof(player), "param should not be null"); } if (when.Kind != DateTimeKind.Utc) { when = when.ToUniversalTime(); } return new Turn(when, player/*, faces*/); } /// /// creates a Turn with a default time, which is "now" in UTC. /// /// player who played the turn /// a new Turn object // TODO add faces public static Turn CreateWithDefaultTime(Player player/*, IEnumerable faces*/) { return CreateWithSpecifiedTime(DateTime.UtcNow, player/*, faces*/); } //TODO add faces /// /// represents a turn in string format /// /// a turn in string format public override string ToString() { //string[] datetime = this.when.ToString("s", System.Globalization.CultureInfo.InvariantCulture).Split("T"); //string date = datetime[0]; //string time = datetime[1]; return String.Format("{0} -- {1} rolled {2}", ToStringIsoWithZ(), this.player.ToString(), ", , ..."); } private string ToStringIsoWithZ() { return this.when.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z"; } } }