public PlayAction PlayCard(IList <Card> allowedCards, IList <Card> currentTrickCards) { var sb = new StringBuilder(); var allowedCardsList = new CardsCollection(allowedCards); allowedCardsList.Sort(this.Contract.Type); for (int i = 0; i < allowedCardsList.Count; i++) { sb.AppendFormat("{0}({1}); ", i + 1, allowedCardsList[i]); } // this.Draw(); while (true) { var action = new PlayAction(); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition(sb.ToString().Trim(), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition("It's your turn! Please select card to play: ", 0, Settings.ConsoleHeight - 3); var cardIndexAsString = Console.ReadLine(); int cardIndex; if (int.TryParse(cardIndexAsString, out cardIndex)) { if (cardIndex > 0 && cardIndex <= allowedCardsList.Count) { var cardToPlay = allowedCardsList[cardIndex - 1]; action.Card = cardToPlay; if (this.hand.IsBeloteAllowed(Contract, currentTrickCards, cardToPlay)) { ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 1); ConsoleHelper.WriteOnPosition("Y(es) / N(o)", 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition("You have belote! Do you want to announce it? Y/N ", 0, Settings.ConsoleHeight - 3); var answer = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(answer) && answer.Trim()[0] == 'N') { action.AnnounceBeloteIfAvailable = false; } } this.hand.Remove(cardToPlay); return(action); } } } }
public void CardsCollection_Sort() { var cards = new CardsCollection() { new Card("Qd"), new Card("Ah"), new Card("2s"), new Card("7d"), new Card("Ts"), new Card("Jc") }; cards.Sort(); Assert.Equal("Ah Qd Jc Ts 7d 2s", cards.ToString()); }
public void Iterate_CardsCollection() { var cards = new CardsCollection() { new Card("Qd"), new Card("Ah"), new Card("2s"), new Card("7d"), new Card("Ts"), new Card("Jc") }; cards.Sort(); var cpt = 0; foreach (var card in cards) { cpt++; } Assert.Equal(cpt, cards.Count); }
public PlayAction PlayCard(IList<Card> allowedCards, IList<Card> currentTrickCards) { var sb = new StringBuilder(); var allowedCardsList = new CardsCollection(allowedCards); allowedCardsList.Sort(this.Contract.Type); for (int i = 0; i < allowedCardsList.Count; i++) { sb.AppendFormat("{0}({1}); ", i + 1, allowedCardsList[i]); } // this.Draw(); while (true) { var action = new PlayAction(); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition(sb.ToString().Trim(), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition("It's your turn! Please select card to play: ", 0, Settings.ConsoleHeight - 3); var cardIndexAsString = Console.ReadLine(); int cardIndex; if (int.TryParse(cardIndexAsString, out cardIndex)) { if (cardIndex > 0 && cardIndex <= allowedCardsList.Count) { var cardToPlay = allowedCardsList[cardIndex - 1]; action.Card = cardToPlay; if (this.hand.IsBeloteAllowed(Contract, currentTrickCards, cardToPlay)) { ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 3); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition(new string(' ', 78), 0, Settings.ConsoleHeight - 1); ConsoleHelper.WriteOnPosition("Y(es) / N(o)", 0, Settings.ConsoleHeight - 2); ConsoleHelper.WriteOnPosition("You have belote! Do you want to announce it? Y/N ", 0, Settings.ConsoleHeight - 3); var answer = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(answer) && answer.Trim()[0] == 'N') { action.AnnounceBeloteIfAvailable = false; } } this.hand.Remove(cardToPlay); return action; } } } }