public void NewPlayTest() { Pile reservePile = new Pile(PileType.Reserve); reservePile.Add(new Card(1)); Pile buildPile = new Pile(PileType.Build); Play play = new Play(reservePile, buildPile); Assert.IsTrue(play.IsValid(), "Play " + play + " should be valid"); }
public void InvalidFromPileIndexTest() { Pile discardPile = new Pile(PileType.Discard); Pile hand = new Pile(PileType.Hand); Pile reservePile = new Pile(PileType.Reserve); Pile drawPile = new Pile(PileType.Draw); Pile buildPile = new Pile(PileType.Build); Card card = new Card(1); Play play = new Play(hand, card, buildPile); Assert.IsFalse(play.IsValid()); hand.Add(card); play = new Play(hand, card, reservePile); Assert.IsFalse(play.IsValid()); }
public void PlayValidityTest() { Pile discardPile = new Pile(PileType.Discard); Pile hand = new Pile(PileType.Hand); Pile reservePile = new Pile(PileType.Reserve); Pile drawPile = new Pile(PileType.Draw); Pile buildPile = new Pile(PileType.Build); Play play; Assert.IsTrue(Board.NumDiscardPiles == Board.NumDiscardPiles); for (int i = 0; i < Board.NumDiscardPiles; i++) { Card card = new Card(1); discardPile.Add(card); play = new Play(discardPile, buildPile); Assert.AreSame(card, play.PlayedCard, "Not expected PlayedCard"); Assert.IsTrue(play.IsValid(), play.ToString()); } Card handCard = new Card(1); hand.Add(handCard); play = new Play(hand, discardPile); Assert.IsTrue(play.ToString().Contains("->")); Assert.AreSame(handCard, play.PlayedCard, "Didn't play expected top hand card"); Assert.IsTrue(play.IsValid(), play.ToString()); Card reserveCard = new Card(1); reservePile.Add(reserveCard); play = new Play(reservePile, discardPile); Assert.AreSame(reserveCard, play.PlayedCard, "Didn't play expected top reserve card"); Assert.IsFalse(play.IsValid(), play.ToString()); Card buildCard = new Card(1); buildPile.Add(buildCard); play = new Play(buildPile, buildCard, discardPile); Assert.AreSame(buildCard, play.PlayedCard, "Didn't play expected top build card"); Assert.IsFalse(play.IsValid(), play.ToString()); Card drawCard = new Card(1); drawPile.Add(drawCard); play = new Play(drawPile, drawCard, hand); Assert.AreSame(drawCard, play.PlayedCard, "Didn't play expected draw card"); Assert.IsTrue(play.IsValid(), string.Format("Draw->Hand should be valid: {0}", play)); }
private static string GenerateErrorMessage(Play play) { return "Invalid Play: " + play; }
public InvalidPlayException(Play play) { _message = GenerateErrorMessage(play); }
private static string GenerateErrorMessage(Play play) { return("Invalid Play: " + play); }
public List<Play> GetValidPlays() { List<Play> plays = new List<Play>(); Pile hand = GetHand(CurrentPlayer); foreach (Card handCard in hand) { foreach (Pile discardPile in _playerDiscardPiles[_currentPlayerIndex]) { Play play = new Play(hand, handCard, discardPile); plays.Add(play); } } return plays; }
// Execute a single-card play for the current player. public void DoPlay(Play play) { if (!play.IsValid()) throw(new InvalidPlayException(play)); if (_isDiscarded) throw (new ApplicationException("No more plays allowed after a discard.")); if (_winner != null) throw (new ApplicationException("No more plays allowed after a winner.")); Card cardFrom = PopCardFromPile(play.FromPile, play.FromCardIndex); play.ToPile.Add(cardFrom); if (play.ToPile.PileType == PileType.Build && play.ToPile.Count == Board.CardUniqueValues) { RecycleBuildPile(play.ToPile); } if (play.ToPileType == PileType.Discard) _isDiscarded = true; if (_playerReservePile[_currentPlayerIndex].Count == 0) { Logger.Write("Winner: " + _currentPlayer); _currentPlayer.WonGame(); _winner = _currentPlayer; _isGameOver = true; } }