コード例 #1
0
        /// <summary>
        /// Generates dates in the given format for the Day DateType with the start and end dates.
        /// </summary>
        /// <param name="inputFormat">The inputDate format</param>
        /// <param name="displayFormat">The display date format</param>
        /// <param name="start">The start date from which to start searching</param>
        /// <param name="end">The end date at which to stop searching</param>
        /// <returns>An array of date strings after applying the rule from the start date to end date.
        /// The format of strings in this array is the display date format.
        /// </returns>
        ///
        /// <remarks>
        /// Due to a design bug, the date must be specified in such a way that the format [DateValue][space][TimeValue]
        /// is in the correct input date format. Conversely, any input date formats not in [DateValue][space][TimeValue]
        /// format are not supported.
        /// </remarks>
        /// <exception cref="RuleInvalidDataException">If the dates could not be generated due to either incorrect
        /// inputFormat/displayFormat or invalid DateValue/TimeValue</exception>
        private string[] GenerateDatesForDayDateType(string inputFormat, string displayFormat,
                                                     DateTime start, DateTime end)
        {
            string          dateAndTime = String.Empty;
            DateTime        parsedDate;
            List <DateTime> ret = new List <DateTime>();

            try
            {
                //Time values may be semi colon delimited
                string[] timeValues = TimeValue.Split(';');
                foreach (string timeValue in timeValues)
                {
                    //Form a [DateValue][space][TimeValue] string
                    dateAndTime = DateValue.TrimEnd() + " " + timeValue.TrimStart();
                    dateAndTime = dateAndTime.Trim();

                    //Try to parse it using inputFormat
                    parsedDate = DateTime.ParseExact(dateAndTime, inputFormat, CultureInfo.InvariantCulture);

                    if (parsedDate.Year % YearDivisor == 0 && parsedDate >= start && parsedDate <= end)
                    {
                        ret.Add(parsedDate);
                    }
                }
            }
            catch (Exception e)
            {
                throw new RuleInvalidDataException(dateAndTime + " is not a valid date for the format : "
                                                   + inputFormat, e);
            }

            return(FormatListAndReturnArray(ret, displayFormat));
        }
コード例 #2
0
        /// <summary>
        /// Parses the TimeValue part to a list of hour and minute pairs.
        /// The TimeValue can be of the form [HH:mm tt;HH:mm tt;.......;HH:mm tt]
        /// </summary>
        /// <returns>a list of hour and minute pairs.</returns>
        /// <exception cref="RuleInvalidDataException">
        /// If the TimeValue format is invalid or
        /// if the parsed hours and minutes are invalid (greater than 23 or 59 respectively)
        /// </exception>
        private IList <KeyValuePair <int, int> > ParseTimeValue()
        {
            IList <KeyValuePair <int, int> > hourMinPairs = new List <KeyValuePair <int, int> >();

            if (TimeValue.Equals(String.Empty))
            {
                //return a single time with hour and min set to zero
                hourMinPairs.Add(new KeyValuePair <int, int>(0, 0));
                return(hourMinPairs);
            }

            //Parse out the times specified (delimited by ;)
            string[] timeValues = TimeValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < timeValues.Length; i++)
            {
                int hour = 0, min = 0;
                try
                {
                    //Here we get the "6:00" part of "6:00 PM" and extract the hour and min parts
                    string onlyTimePart = timeValues[i].Split(' ')[0];
                    hour += int.Parse(onlyTimePart.Split(':')[0]);
                    min  += int.Parse(onlyTimePart.Split(':')[1]);

                    //12:35 AM is actually 00:35
                    //12:35 PM is not 24:35
                    if (timeValues[i].Contains("PM") && hour < 12)
                    {
                        hour += 12;
                    }
                    if (timeValues[i].Contains("AM") && hour == 12)
                    {
                        hour -= 12;
                    }
                }
                catch (Exception e)
                {
                    throw new RuleInvalidDataException(
                              timeValues[i] + " must be in format: '[hour]:[minute] [AM/PM]'.", e);
                }

                if (hour > 23 || min > 59)
                {
                    throw new RuleInvalidDataException(timeValues[i] + " is an invalid time.");
                }

                //Add each time parsed to the list.
                hourMinPairs.Add(new KeyValuePair <int, int>(hour, min));
            }

            return(hourMinPairs);
        }
コード例 #3
0
        public void timeExtracter()
        {
            String[] word  = TimeValue.Split(':', ' ');
            String[] array = { "0", "0", "0" };
            int      c     = 0;

            foreach (String words in word)
            {
                array[c] = words;
                c++;
            }
            int number  = Convert.ToInt32(array[1]);
            int number1 = Convert.ToInt32(array[0]);

            number += 1;
            if (number >= 60)
            {
                number1 = number - 60;
            }
            array[1] = number.ToString();
            array[0] = number1.ToString();
            if (int.Parse(array[0]) < 10)
            {
                TimeHrs = "0" + array[0];
            }
            else
            {
                TimeHrs = array[0];
            }

            if (int.Parse(array[1]) < 10)
            {
                TimeMins = "0" + array[1];
            }
            else
            {
                TimeMins = array[1];
            }

            TimeAmPm = array[2].ToUpper();
        }
コード例 #4
0
ファイル: ActorMap.cs プロジェクト: BlayeeR/BoulderDash
        public void LoadContent(ContentManager content)
        {
            //i = row y, j column x
            for (int i = 0; i < raw.Count; i++)
            {
                for (int j = 0; j < raw[i].Length; j++)
                {
                    Actor actor = null;
                    using (ContentManager c = new ContentManager(content.ServiceProvider, content.RootDirectory))
                    {
                        switch (raw[i][j])
                        {
                        case 'W':
                        {
                            actor = c.Load <Actor>("Actors/Border");
                            break;
                        }

                        case 'X':
                        {
                            actor  = c.Load <Actor>("Actors/Player");
                            Player = actor;
                            break;
                        }

                        case '.':
                        {
                            actor = c.Load <Actor>("Actors/Dirt");
                            break;
                        }

                        case 'w':
                        {
                            actor = c.Load <Actor>("Actors/Wall");
                            break;
                        }

                        case 'r':
                        {
                            actor = c.Load <Actor>("Actors/Boulder");
                            break;
                        }

                        case 'd':
                        {
                            actor = c.Load <Actor>("Actors/Diamond");
                            break;
                        }

                        case 'P':
                        {
                            actor = c.Load <Actor>("Actors/Exit");
                            break;
                        }
                        }
                    }
                    if (actor != null)
                    {
                        actor.Owner = this;
                        actor.LoadContent(content);
                        actor.GetComponent <RenderableComponent>().DrawColor = ForegroundColor;
                        actor.Position = new Vector2(j * TileDimensions.X, i * TileDimensions.Y);
                        Actors.Add(actor);
                    }
                }
            }
            Actors.Where(x => x.HasComponent <ExitComponent>()).ToList().ForEach(x => x.GetComponent <ExitComponent>().ExitEntered             += ActorMap_ExitEntered);
            Actors.Where(x => x.HasComponent <DestroyableComponent>()).ToList().ForEach(x => x.GetComponent <DestroyableComponent>().Destroyed += ActorMap_ActorDestroyed);
            Actors.Where(x => x.HasComponent <PlayerComponent>()).ToList().ForEach(x => x.GetComponent <PlayerComponent>().PlayerKilled        += ActorMap_PlayerKilled);
            Actors.Where(x => x.HasComponent <CollectableComponent>()).ToList().ForEach(x => x.GetComponent <CollectableComponent>().Collected += ActorMap_Collected);

            //force 1lvl
            Time             = Int32.Parse(TimeValue.Split(" ").FirstOrDefault());
            DiamondsRequired = Int32.Parse(DiamondsRequiredValue.Split(" ").FirstOrDefault());

            Size = new Vector2(Actors.Last().Position.X - Actors[0].Position.X + TileDimensions.X, Actors.Last().Position.Y - Actors[0].Position.Y + TileDimensions.Y);
            InputManager.Instance.OnFlickDown  += Instance_OnFlickDown;
            InputManager.Instance.OnFlickUp    += Instance_OnFlickUp;
            InputManager.Instance.OnFlickLeft  += Instance_OnFlickLeft;
            InputManager.Instance.OnFlickRight += Instance_OnFlickRight;
            MapStartSound = content.Load <Song>("Sounds/MapStart");
            MapEndSound   = content.Load <Song>("Sounds/MapComplete");
            MapLoaded?.Invoke(this, null);
            MediaPlayer.Play(MapStartSound);
        }