Exemplo n.º 1
0
        /// <summary>
        /// Gets a tile with given letter
        /// If not available, retrieves a blank
        /// </summary>
        /// <param name="c">Letter of tile to pick</param>
        /// <returns></returns>
        public CharTile GetTile(char c)
        {
            CharTile             tile      = null;
            List <Rack_CharTile> rackTiles = Rack_CharTiles.ToList();
            var tileEntryInDb = rackTiles.Where(t => t.CharTile.Letter == c && t.CharTile.Score != 0).FirstOrDefault();

            if (tileEntryInDb == null)
            {
                tileEntryInDb = rackTiles.Where(x => x.CharTile.Letter == '*').FirstOrDefault();
            }
            tile = tileEntryInDb.CharTile;
            return(tile);
        }
Exemplo n.º 2
0
        public void AddToPouch(CharTile tile)
        {
            List <Pouch_CharTile> pouchTiles = Pouch_CharTiles.ToList();
            var tileEntryInDb = Pouch_CharTiles.Where(c => c.ID == tile.ID).FirstOrDefault();

            if (tileEntryInDb == null)
            {
                pouchTiles.Add(new Pouch_CharTile {
                    CharTileID = tile.ID, PouchID = ID, Count = 1
                });
            }
            else
            {
                tileEntryInDb.Count++;
            }
            Pouch_CharTiles = pouchTiles;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Remoces tile from rack
        /// </summary>
        /// <param name="tile">Tile object to remove</param>
        public void SubstractFromRack(CharTile tile)
        {
            List <Rack_CharTile> rackTiles = Rack_CharTiles.ToList();
            var tileEntryInDb = rackTiles.Where(c => c.CharTileID == tile.ID).FirstOrDefault();

            if (tileEntryInDb == null)
            {
                tileEntryInDb = rackTiles.Where(x => x.CharTile.Letter == '*').FirstOrDefault();
            }
            if (tileEntryInDb.Count == 1)
            {
                rackTiles.RemoveAll(c => c.CharTileID == tileEntryInDb.CharTile.ID);
            }
            else
            {
                tileEntryInDb.Count--;
            }
            Rack_CharTiles = rackTiles;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Removes tile with letter from rack
        /// If no such tile is available, a blank tile is removed
        /// </summary>
        /// <param name="c">Letter of tile to remove</param>
        /// <returns></returns>
        public CharTile SubstractFromRack(char c)
        {
            CharTile             tile      = null;
            List <Rack_CharTile> rackTiles = Rack_CharTiles.ToList();
            var tileEntryInDb = rackTiles.Where(t => t.CharTile.Letter == c && t.CharTile.Score != 0).FirstOrDefault();

            if (tileEntryInDb == null)
            {
                tileEntryInDb = rackTiles.Where(x => x.CharTile.Letter == '*').FirstOrDefault();
            }
            tile = tileEntryInDb.CharTile;
            if (tileEntryInDb.Count == 1)
            {
                rackTiles.RemoveAll(t => t.CharTile.Letter == tileEntryInDb.CharTile.Letter &&
                                    t.CharTile.Score == tileEntryInDb.CharTile.Score);
            }
            else
            {
                tileEntryInDb.Count--;
            }
            Rack_CharTiles = rackTiles;
            return(tile);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds tile to rack
        /// </summary>
        /// <param name="tile">Tile to add</param>
        public void AddToRack(CharTile tile)
        {
            List <Rack_CharTile> rackTiles = Rack_CharTiles.ToList();
            var tileCount = 0;

            foreach (var entry in rackTiles)
            {
                tileCount += entry.Count;
            }
            var tileEntryInDb = rackTiles.Where(c => c.CharTileID == tile.ID).FirstOrDefault();

            if (tileEntryInDb == null)
            {
                rackTiles.Add(new Rack_CharTile {
                    CharTileID = tile.ID, RackID = ID, Count = 1, CharTile = tile, Rack = this
                });
            }
            else
            {
                tileEntryInDb.Count++;
            }
            Rack_CharTiles = rackTiles;
        }