Beispiel #1
0
        /// <summary>
        /// Adds the specified element to the record group.
        /// </summary>
        /// <param name="element">The element to add to the group.</param>
        public void AddElement(IRecordItem element) {
            elements.Add(element);

            if (element is IRecordElement)
            {
                elementTracker.AddElement(element as IRecordElement);
            }
        }
Beispiel #2
0
        public bool IsRecord(GameType gameType, int seconds)
        {
            if (records == null)
            {
                return(true);
            }

            IRecordItem ri = records.FirstOrDefault(r => r.GameType == gameType);

            if (ri == null)
            {
                return(true);
            }

            return(ri.Time > seconds);
        }
Beispiel #3
0
        public void AddNewRecordWithAnotherGameType()
        {
            Records records = new Records();

            GameType gameType   = GameType.Newbie;
            int      recordTime = 10;
            string   playerName = "Вася Пупкин";

            records.UpdateRecord(gameType, recordTime, playerName);

            GameType anotherType = GameType.Professional;
            int      anotherTime = 15;
            string   anotherName = "Иванов";

            records.UpdateRecord(anotherType, anotherTime, anotherName);

            var         results = records.GetRecords();
            IRecordItem item    = results.First(r => r.GameType == anotherType);

            Assert.AreEqual(anotherTime, item.Time);
            Assert.AreEqual(anotherName, item.Player);
        }
Beispiel #4
0
        public void UpdateRecord(GameType gameType, int seconds, string player)
        {
            if (gameType == GameType.Custom)
            {
                throw new ArgumentException("Невозможно добавить рекорд для случайной игры.");
            }

            if (records == null)
            {
                records = new List <IRecordItem>(RecordListSize);
            }

            IRecordItem ri         = records.FirstOrDefault(r => r.GameType == gameType);
            RecordItem  recordItem = (RecordItem)ri;

            if (recordItem != null)
            {
                if (recordItem.Time < seconds)
                {
                    throw new ArgumentException($"Прошлый рекорд для этого типа игры {recordItem.Time} секунд. Время нового рекорда должно быть меньше.");
                }

                recordItem.Time   = seconds;
                recordItem.Player = player;
            }
            else
            {
                RecordItem newRecord = new RecordItem
                {
                    GameType = gameType,
                    Time     = seconds,
                    Player   = player
                };
                records.Add(newRecord);
            }

            OnRecordChanged?.Invoke(this, EventArgs.Empty);
        }