2022 - No error message is displayed if the user attempts to play two consecutive cards of the same tool type

From TRCCompSci - AQA Computer Science
Revision as of 13:00, 22 December 2021 by Admin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You will first need to find the PlayCardToSequence method in the BreakThrough Class:

 private void PlayCardToSequence(int cardChoice)
        {
            if (Sequence.GetNumberOfCards() > 0)
            {
                if (Hand.GetCardDescriptionAt(cardChoice - 1)[0] != Sequence.GetCardDescriptionAt(Sequence.GetNumberOfCards() - 1)[0])
                {
                    Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(cardChoice - 1));
                    GetCardFromDeck(cardChoice);
                }
            }
            else
            {
                Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(cardChoice - 1));
                GetCardFromDeck(cardChoice);
            }
            if (CheckIfLockChallengeMet())
            {
                Console.WriteLine();
                Console.WriteLine("A challenge on the lock has been met.");
                Console.WriteLine();
                Score += 5;
            }
        }

The first if statement 'if (Sequence.GetNumberOfCards() > 0)' is to check if cards have been played to the sequence. If no cards have been played the GetNumberOfCards will return 0.

The second if statement (embedded into the if true section of the first) above is what stop you playing a card of the same type as the previous. It checks a the card description of the card in the hand with the card discription of the last card played to the sequence. i.e. just this bit:

 if (Hand.GetCardDescriptionAt(cardChoice - 1)[0] != Sequence.GetCardDescriptionAt(Sequence.GetNumberOfCards() - 1)[0])
                {
                    Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(cardChoice - 1));
                    GetCardFromDeck(cardChoice);
                }

What you need to do

  • Add an else condition to the second if statement.