コード例 #1
0
        /**
         * Removes the tiles of the specified Color from this collection, and returns them in a new collection.
         *
         * @param c
         *            the Color of tiles to remove
         * @return the removed tiles
         */
        public TileCollection removeTilesOfColor(Color c)
        {
            TileCollection tc = new TileCollection();

            for (int i = 0; i < Count; ++i)
            {
                if (this[i] == c)
                {
                    tc.Add(remove(i--)); // '--' here because we removed an element
                }
            }
            return(tc);
        }
コード例 #2
0
        /**
         * Selects the specified number of tiles (Color objects) randomly from this collection. If the number of tiles to
         * draw is larger than the size of this collection, then only as many tiles as are in this collection are drawn. The
         * selected tiles are removed from this collection.
         *
         * @param num
         *            the number of tiles to draw
         * @return a new TileCollection containing the drawn tiles
         * @throws IllegalArgumentException
         *             if the parameter is negative
         */
        public TileCollection drawTiles(int num)
        {
            if (num < 0)
            {
                throw new ArgumentOutOfRangeException("num", "Cannot draw negative tiles.");
            }
            TileCollection drawn = new TileCollection();

            if (num > Count)
            {
                num = Count;
            }
            for (int i = 0; i < num; ++i)
            {
                drawn.Add(remove((int)(Utils.rand() * Count)));
            }
            return(drawn);
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: Jsnhlbr5/Azul-C-Sharp
 private void resetCenter()
 {
     for (int i = 0; i < factories.Length; ++i)
     {
         factories[i] = bag.drawTiles(4);
         if (factories[i].Count < 4)
         {
             if (!boxLid.Empty)
             {
                 bag.AddRange(boxLid);
                 boxLid.Clear();
                 factories[i].AddRange(bag.drawTiles(4 - factories[i].Count));
             }
             else
             {
                 // No more tiles to draw, remaining factories will be empty.
                 break;
             }
         }
     }
     centerArea.Add(Color.WHITE);
     UpdateTiles();
 }