예제 #1
0
 private void CheckValidity(Card card, Player player)
 {
     if (card == null)
     {
         isValidCardPlayed = false;
         Console.WriteLine("Please select an existing card");
         return;
     }
     if (!Game.GetPlayingTable().Any() && !Game.firstPlayed)
     {
         if (card.suit == CardInfo.GetSuit("clubs") && card.number == CardInfo.GetNumber("2"))
         {
             Game.firstPlayed  = true;
             isValidCardPlayed = true;
         }
         else
         {
             Console.WriteLine("Please play 2 of clubs");
             isValidCardPlayed = false;
             player.hand.PushCard(card);
         }
     }
     else if (!Game.GetPlayingTable().Any())
     {
         if (card.suit == CardInfo.GetSuit("Hearts"))
         {
             if (Game.heartsBreak)
             {
                 isValidCardPlayed = true;
             }
             else
             {
                 if (player.hand.Contains(CardInfo.GetSuit("Clubs")) ||
                     player.hand.Contains(CardInfo.GetSuit("Spades")) ||
                     player.hand.Contains(CardInfo.GetSuit("Diamonds")))
                 {
                     Console.WriteLine("Hearts has not been broken yet.");
                     isValidCardPlayed = false;
                     player.hand.PushCard(card);
                 }
                 else
                 {
                     isValidCardPlayed = true;
                     Game.heartsBreak  = true;
                 }
             }
         }
         else
         {
             isValidCardPlayed = true;
         }
     }
     else
     {
         Card temp       = Game.GetPlayingTable().ElementAt(0);
         bool isSuitExit = player.hand.Contains(temp.suit);
         if (isSuitExit)
         {
             if (temp.suit == card.suit)
             {
                 isValidCardPlayed = true;
             }
             else
             {
                 Console.WriteLine("Please play a valid card");
                 isValidCardPlayed = false;
                 player.hand.PushCard(card);
             }
         }
         else
         {
             if (temp.suit == CardInfo.GetSuit("Clubs") && temp.number == CardInfo.GetNumber("2"))
             {
                 if (card.suit == CardInfo.GetSuit("Spades") && card.number == CardInfo.GetNumber("Queen"))
                 {
                     Console.WriteLine("Spades of Queen can not be played at first turn");
                     isValidCardPlayed = false;
                     player.hand.PushCard(card);
                 }
                 else if (card.suit == CardInfo.GetSuit("Hearts"))
                 {
                     if (player.hand.Contains(CardInfo.GetSuit("Clubs")) ||
                         player.hand.Contains(CardInfo.GetSuit("Spades")) ||
                         player.hand.Contains(CardInfo.GetSuit("Diamonds")))
                     {
                         Console.WriteLine("Hearts can not be played at first turn.");
                         isValidCardPlayed = false;
                         player.hand.PushCard(card);
                     }
                     else
                     {
                         isValidCardPlayed = true;
                         Game.heartsBreak  = true;
                     }
                 }
                 else
                 {
                     isValidCardPlayed = true;
                 }
             }
             else
             {
                 isValidCardPlayed = true;
                 if (card.suit == CardInfo.GetSuit("Hearts"))
                 {
                     Game.heartsBreak = true;
                 }
             }
         }
     }
 }