using System; using Model.Players; namespace Model.Games { /// /// 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; // ... faces /// /// this private constructor is to be used only by factories /// /// date and time of the turn /// player who played the turn // ... faces private Turn(DateTime when, Player player/*, IEnumerable faces*/) { this.when = when; this.player = player; // ... 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 // ... faces public static Turn CreateWithSpecifiedTime(DateTime when, Player player/*, IEnumerable faces*/) { // ... faces 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 // ... faces public static Turn CreateWithDefaultTime(Player player/*, IEnumerable faces*/) { return CreateWithSpecifiedTime(DateTime.UtcNow, player/*, faces*/); } // ... faces /// /// represents a turn in string format /// /// a turn in string format public override string ToString() { return string.Format("{0} -- {1} rolled {2}", ToStringIsoWithZ(), player.ToString(), ", , ..."); } private string ToStringIsoWithZ() { return when.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + "Z"; } } }