/// <summary> /// Stack the deck. /// </summary> /// <returns>The deck stacked.</returns> public PlayingDeck GetDeck() { PlayingDeck returnValue = new PlayingDeck(); returnValue.BackImage = String.Empty; returnValue.Name = String.Empty; returnValue.UndealtCards = new List<PlayingCard>(); PlayingCard card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "Ace of Spades"; card.Value = 14; returnValue.UndealtCards.Add(card); card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "Ace of Diamonds"; card.Value = 14; returnValue.UndealtCards.Add(card); card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "King of Hearts"; card.Value = 13; returnValue.UndealtCards.Add(card); return returnValue; }
/// <summary> /// Shuffle the deck randomly. /// </summary> /// <param name="deck">The deck to shuffle.</param> /// <remarks>This shuffles the deck with one of the best .NET randomization algorithms. The algorithm is used in encryption.</remarks> public void ShuffleDeck(PlayingDeck deck) { RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); int n = deck.UndealtCards.Count; while (n > 1) { byte[] box = new byte[1]; do provider.GetBytes(box); while (!(box[0] < n * (Byte.MaxValue / n))); int k = (box[0] % n); n--; PlayingCard value = deck.UndealtCards[k]; deck.UndealtCards[k] = deck.UndealtCards[n]; deck.UndealtCards[n] = value; } }
/// <summary> /// Construct a new game object. /// </summary> /// <param name="player1">The first player.</param> /// <param name="player2">The second player.</param> /// <param name="deck">The deck to play with.</param> /// <param name="pathToLogFile">The path to the log file for this game.</param> public Game(GamePlayer player1, GamePlayer player2, PlayingDeck deck, string pathToLogFile) { #region Param Checking if (player1 == null) { throw new ArgumentNullException("player1"); } if (player2 == null) { throw new ArgumentNullException("player2"); } if (deck == null) { throw new ArgumentNullException("deck"); } if (String.IsNullOrWhiteSpace(pathToLogFile)) { throw new ArgumentNullException(pathToLogFile); } try { Path.GetFullPath(pathToLogFile); } catch (Exception ex) { throw new ArgumentException("The path to the log file is not valid. See inner exception for details.", ex); } #endregion this.Player1 = player1; this.Player2 = player2; this.Deck = deck; this.Status = GameStatus.NotStarted; this.PathToGameLog = pathToLogFile; }
/// <summary> /// No shuffling allowed. /// </summary> /// <param name="deck">The deck to shuffle.</param> public void ShuffleDeck(PlayingDeck deck) { //Do nothing. }