public Card Defend(List <Card> CardsOnTable, List <Card> CardsOnHands, Card CardToBeat) { List <Card> possibleDefendCards = PossibleDefendCards(CardsOnHands, CardToBeat); Card minCardNonTrump = null; Card minCardTrump = null; if (possibleDefendCards.Count != 0) { minCardNonTrump = ChooseMinRankCard(possibleDefendCards, false); minCardTrump = ChooseMinRankCard(possibleDefendCards, true); if (minCardNonTrump == null) // there are no NonTrump cards on Hands { Console.WriteLine($"{_message.cpuBeatWith_32_} {minCardTrump.Name},{(minCardTrump.Suit).ToUpper()}"); //CPU covered with return(minCardTrump); } else { Console.WriteLine($"{_message.cpuBeatWith_32_} {minCardNonTrump.Name},{minCardNonTrump.Suit}"); return(minCardNonTrump); } } else { Console.WriteLine($"{_message.cpuHasNoDefendCard_33_}"); //CPU has no cards to defend, press any key to continue _consoleRead.ConsoleReadKey(); return(null); } }
//check if Player chose right card to beat CardsOnHands or PossibleAttackCards public Card Attack(List <Card> CardsOnHands, List <Card> CardsOnTable) { string Input = null; int Enter = 0; bool Continue = true; List <Card> possibleAttackCards = null; if (CardsOnTable.Count != 0) { possibleAttackCards = PossibleAttackCards(CardsOnHands, CardsOnTable); } else { possibleAttackCards = CardsOnHands; } Console.WriteLine($"{_message.chooseAttackCard_3_}"); //Choose the card to attack or print 100 to skip! if (possibleAttackCards.Count != 0) { if (CardsOnTable.Count != 0) { Console.WriteLine($"{_message.youMayUseTheseCards_4_}"); // You may use these card(s): foreach (Card i in possibleAttackCards) { if (i.Trump == false && CardsOnTable != null) { Console.WriteLine($"{i.Name} , {i.Suit}"); } else { Console.WriteLine($"{i.Name} , {(i.Suit).ToUpper()}"); } } } Card Temp = null; while (Continue) { Input = _consoleRead.ConsoleReadLine(); bool Cont = true; while (Cont) { try { int m = Convert.ToInt32(Input); Cont = false; } catch (Exception) { Console.WriteLine($"{_alert.enterInteger_1_}"); //You should enter an integer Input = _consoleRead.ConsoleReadLine(); } } Enter = int.Parse(Input); if (Enter > 0 && Enter <= CardsOnHands.Count) { foreach (Card i in possibleAttackCards) { if (CardsOnHands[Enter - 1].Equals(i)) { Temp = CardsOnHands[Enter - 1]; Continue = false; } else { Console.WriteLine($"{_message.youCannotUseCard_5_}"); //You can not use this card } } } else if (Enter > CardsOnHands.Count && Enter != 100) { Console.WriteLine($"{_alert.enterNotBiggerThan_2_} {CardsOnHands.Count}"); //Enter not bigger than } else if (Enter == 100) { Continue = false; } else if (Enter <= 0) { Console.WriteLine($"{_alert.enterPositiveNumber_3_}"); //Enter positive number } } return(Temp); } Console.WriteLine($"{_message.haveNoCardsToAttack_6_}"); //You have no cards to attack, press any key to continue _consoleRead.ConsoleReadKey(); return(null); }