コード例 #1
0
        ///<summary>
        /// Calculates if the animal is still alive. Uses the util Date to determinate the
        /// difference in minutes between the last_wash and last_food attributes and their
        /// respective limits
        ///</summary>
        ///<returns>
        /// false if one of the limits was exceeded
        ///</returns>
        public bool IsAlive()
        {
            if (Dates.IsGreatter(this.LastWash, this.LimitWash))
            {
                this.Alive = false;
            }

            if (Dates.IsGreatter(this.LastFood, this.LimitFood))
            {
                this.Alive = false;
            }

            return(this.Alive);
        }
コード例 #2
0
        ///<summary>
        /// returns the Animal info.
        ///</summary>
        ///<returns>
        /// the full Animal info
        ///</returns>
        public string GetInfo()
        {
            string character = this.GetCharacter();
            string animal    = "";

            animal += new string('#', 50) + "\n";
            animal += character + "\n";
            animal += "Name: " + this.Name + "\n";
            animal += "Alive: " + this.IsAlive() + "\n";
            animal += "Sound: " + this.Speak() + "\n";
            animal += "Wash time limit: " + (this.LimitWash - Dates.GetDiffInMinutes(this.LastWash)) + "\n";
            animal += "Food time limit: " + (this.LimitFood - Dates.GetDiffInMinutes(this.LastFood)) + "\n";
            animal += new string('#', 50) + "\n";

            return(animal);
        }
コード例 #3
0
        ///<summary>
        /// Returns the difference between the current date and the given date.
        ///</summary>
        ///<param name="date">date to compare with the current date.</param>
        ///<returns>
        /// true if the difference doesn't exceeds the limit
        ///</returns>
        public static long GetDiffInMinutes(DateTime date)
        {
            DateTime now = DateTime.Now;

            return(Dates.DiffInMinutes(date, now));
        }
コード例 #4
0
 ///<summary>
 /// Returns if a date exceeds a limit.
 ///</summary>
 ///<param name="date">date to compare with the current date.</param>
 ///<param name="limit">difference limit in minutes between the dates.</param>
 ///<returns>
 /// true if the difference doesn't exceeds the limit
 ///</returns>
 public static bool IsGreatter(DateTime date, int limit)
 {
     return(Dates.GetDiffInMinutes(date) > limit);
 }