/// <summary> /// Refills rack up to its maximum size /// </summary> public void RefillRackFromPouch() { List <Rack_CharTile> rackTiles = Rack_CharTiles.ToList(); int countOfRackTiles = GetCountOfTilesInRack(); for (int i = countOfRackTiles; i < RackSize; i++) { var randomTile = Pouch.PickRandomTile(); if (randomTile == null) { break; } if (rackTiles.Any(t => t.CharTileID == randomTile.ID)) { var tileEntryInDb = rackTiles.Where(t => t.CharTileID == randomTile.ID).FirstOrDefault(); tileEntryInDb.Count++; } else { rackTiles.Add(new Rack_CharTile { RackID = ID, CharTileID = randomTile.ID, Count = 1 }); } } Rack_CharTiles = rackTiles; }
/// <summary> /// Trades some of their rack tiles for new ones from the pouch /// </summary> public void Redraw(string letters, string counts) { var lettersArray = letters.Split(","); var countsArray = counts.Split(","); var rack = Rack.Rack_CharTiles.ToList(); var tilesToDraw = 0; for (int i = 0; i < lettersArray.Length; i++) { for (int j = 0; j < Int32.Parse(countsArray[i]); j++) { Pouch.AddToPouch(Rack.SubstractFromRack(lettersArray[i][0])); tilesToDraw++; } } Rack.RefillRackFromPouch(); }