예제 #1
0
        /// <summary>
        /// Constructor for Ailment
        /// </summary>
        /// <param name="id">String holding ailment ID</param>
        /// <param name="descr">string holding ailment description</param>
        /// <param name="wh">string holding ailment date</param>
        /// <param name="eff">uint holding current ailment effect</param>
        /// <param name="minEff">uint holding minimum ailment effect</param>
        public Ailment(String id, string descr, string wh, uint eff, uint minEff)
        {
            // VALIDATION

            // ID
            // trim and ensure 1st is uppercase
            id = Utility_Methods.FirstCharToUpper(id.Trim());

            if (!Utility_Methods.ValidateAilmentID(id))
            {
                throw new InvalidDataException("Ailment ID must have the format 'Ail_' followed by some numbers");
            }

            // DESCR
            // trim and ensure 1st is uppercase
            descr = Utility_Methods.FirstCharToUpper(descr.Trim());

            if (!Utility_Methods.ValidateName(descr))
            {
                throw new InvalidDataException("Ailment description must be 1-40 characters long and contain only valid characters (a-z and ') or spaces");
            }

            // WHEN
            // trim and ensure 1st is uppercase
            wh = Utility_Methods.FirstCharToUpper(wh.Trim());

            // check contains season
            if (!wh.Contains("Spring"))
            {
                if (!wh.Contains("Summer"))
                {
                    if (!wh.Contains("Autumn"))
                    {
                        if (!wh.Contains("Winter"))
                        {
                            throw new InvalidDataException("Ailment 'when' must specify the season and year in which the ailment occurred");
                        }
                    }
                }
            }

            // EFF
            // check must be 1-5
            if ((eff < 1) || (eff > 5))
            {
                throw new InvalidDataException("Ailment effect must be a uint between 1-5");
            }

            // MINEFF
            // check not > 1
            if (minEff > 1)
            {
                throw new InvalidDataException("Ailment minimumEffect must be a uint less than 2");
            }

            this.ailmentID     = id;
            this.description   = descr;
            this.when          = wh;
            this.effect        = eff;
            this.minimumEffect = minEff;
        }