Exemplo n.º 1
0
 public void Reset()
 {
     for (int index = 0; index < this._items.Count; ++index)
     {
         GrabBagItem <T> grabBagItem = this._items[index];
         grabBagItem.IsTaken = false;
         this._items[index]  = grabBagItem;
     }
 }
Exemplo n.º 2
0
        public bool Take(T item)
        {
            int index = this._items.FindIndex((Predicate <GrabBagItem <T> >)(x => EqualityComparer <T> .Default.Equals(x.Value, item)));

            if (index == -1 || this._items[index].IsTaken)
            {
                return(false);
            }
            GrabBagItem <T> grabBagItem = this._items[index];

            grabBagItem.IsTaken = true;
            this._items[index]  = grabBagItem;
            return(true);
        }
Exemplo n.º 3
0
        public T TakeRandom()
        {
            if (this._items.Count == 0)
            {
                throw new InvalidOperationException("No items to take.");
            }
            int num = this._rand.Next(this._items.Count);

            for (int index1 = 0; index1 < this._items.Count; ++index1)
            {
                int index2 = (index1 + num) % this._items.Count;
                if (!this._items[index2].IsTaken)
                {
                    GrabBagItem <T> grabBagItem = this._items[index2];
                    grabBagItem.IsTaken = true;
                    this._items[index2] = grabBagItem;
                    return(this._items[index2].Value);
                }
            }
            throw new InvalidOperationException("All items are taken.");
        }