Пример #1
0
    public bool MoveNext(out Removable current)
    {
        current = default;
        T   item;
        int i;

        lock (_locker)
        {
            _currentIndex--;
            i = _currentIndex;
            if (i < 0)
            {
                return(false);
            }
            item = _list[i];
        }
        current = new Removable(item, () =>
        {
            lock (_locker)
            {
                var index = _indexes.BinarySearch(i);
                _indexes.RemoveAt(index);
                _list.RemoveAt(index);
            }
        });
        return(true);
    }
Пример #2
0
        public override void update(float t, float dt)
        {
            //fpsCounter.update(dt);
            //var fps = string.Format("FPS: {0}", fpsCounter.currentFramesPerSecond);
            //setTitle(fps);
            var bricksAlive = 0;

            var entities = Engine.Engine.getInst().entities;

            foreach (Entity entity in entities.Values)
            {
                var brickStatus = entity.getComponent <BrickStatus>();
                var score       = entity.getComponent <Score>();
                if (brickStatus != null && !brickStatus.alive)
                {
                    pointsToAdd += 10;
                    Removable remove = entity.getComponent <Removable>();
                    remove.remove = true;
                }

                if (score != null)
                {
                    score.score += pointsToAdd;
                    pointsToAdd  = 0;
                    if (score.gameOver)
                    {
                        score.gameOver = false;
                        ballsInPlay--;
                        if (ballsInPlay == 0)
                        {
                            resetGame(true);
                            score.score = 0.0f;
                            break;
                        }
                    }
                }
            }

            foreach (Entity entity in entities.Values)
            {
                var brickStatus = entity.getComponent <BrickStatus>();
                if (brickStatus != null && brickStatus.alive)
                {
                    bricksAlive++;
                }
            }

            if (bricksAlive == 0)
            {
                resetGame(false);
            }
        }
Пример #3
0
        public IList <string> Remove(IList <string> words, Removable item)
        {
            CheckWords(words, "words");

            List <string> cleanText = new List <string>();

            foreach (string word in words)
            {
                cleanText.Add(Remove(word, item));
            }

            return(cleanText);
        }
Пример #4
0
        private void clearOldEntites(Dictionary <int, Entity> entities)
        {
            int[] indexToRemove = new int[entities.Count];
            int   i             = 0;

            foreach (var entity in entities.Values)
            {
                Removable remove = entity.getComponent <Removable>();
                if (remove != null && remove.remove)
                {
                    indexToRemove[i++] = entity.id;
                }
            }


            for (i = 0; i < indexToRemove.Length; i++)
            {
                entities.Remove(indexToRemove[i]);
            }
        }
Пример #5
0
        public string Remove(string text, Removable item)
        {
            CheckText(text, "text");

            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.Html))
            {
                text = RemoveHtml(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.NoBreakSpace))
            {
                text = RemoveNoBreakSpace(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.Possesion))
            {
                text = TransformPossession(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.IllegalXmlChars))
            {
                text = RemoveIllegalXmlCharacters(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.SpecialChars))
            {
                text = RemoveSpecialCharacters(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.SpecialCharOnlyWords))
            {
                text = RemoveSpecialCharacterOnlyWords(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.NewLineCharacters))
            {
                text = RemoveNewLineCharacters(text);
            }
            if (item.HasFlag(Removable.All) || item.HasFlag(Removable.ExtraSpaces))
            {
                text = RemoveExtraSpaces(text);
            }

            return(text);
        }
Пример #6
0
        private void updateVelocity(float dt, Entity entity, Velocity velocity, Position position, Score score, Sprite sprite, Dictionary <int, Entity> entities)
        {
            position.y += velocity.y * dt;
            position.x += velocity.x * dt;

            // Fix paddle position to prevent drifting away.
            if (score != null && position.y < Engine.getInst().GraphicsDevice.Viewport.Height - 25)
            {
                position.y = Engine.getInst().GraphicsDevice.Viewport.Height - 25;
                velocity.y = 0.0f;
            }


            // Hit top
            if (position.y - (sprite.texture.Height * 0.5f) < 0)
            {
                velocity.y *= -1;
            }

            // Hit sides
            if (position.x > Engine.getInst().GraphicsDevice.Viewport.Width - (sprite.texture.Width * 0.5f) ||
                position.x - (sprite.texture.Width * 0.5f) < 0)
            {
                velocity.x *= -1;
            }

            // "Gravity" on paddle speed
            if (score != null)
            {
                velocity.x += ((velocity.x * -1) * dt) * 1.5f;
            }

            // Hit bottom
            if (score == null && position.y > Engine.getInst().GraphicsDevice.Viewport.Height - (sprite.texture.Height * 0.5f))
            {
                Removable remove = entity.getComponent <Removable>();
                remove.remove = true;
                foreach (var ent in entities.Values)
                {
                    var sco = ent.getComponent <Score>();
                    if (sco != null)
                    {
                        sco.gameOver = true;
                        break;
                    }
                }
            }
            else if (position.y > Engine.getInst().GraphicsDevice.Viewport.Height - (sprite.texture.Height * 0.5f))
            {
                velocity.y *= -1;
            }

            // Clamp in view

            position.x = MathHelper.Clamp(position.x,
                                          (sprite.texture.Width * 0.5f),
                                          Engine.getInst().GraphicsDevice.Viewport.Width - (sprite.texture.Width * 0.5f));
            position.y = MathHelper.Clamp(position.y,
                                          (sprite.texture.Height * 0.5f),
                                          Engine.getInst().GraphicsDevice.Viewport.Height - (sprite.texture.Height * 0.5f));
        }
 /// <summary>
 /// Remove an item from the <see cref="IPagedDataSet"/> with the specified position
 /// </summary>
 /// <param name="dataSet">The dataset to modify</param>
 /// <param name="offset">The position to remove relative to the dataset's caret</param>
 /// <returns></returns>
 public static Task RemoveAtOffset <TItem, TResult>(this Removable <TItem, TResult> removable, int offset) where TItem : class
 => removable.RemoveAtOffset(removable.PagedDataSet, offset);