Difference between revisions of "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
Jump to: navigation, search
(Created page with "You will first need to find the PlayCardToSequence method in the BreakThrough Class: <syntaxhighlight lang=c#> private void PlayCardToSequence(int cardChoice) {...")
 
 
Line 26: Line 26:
 
         }
 
         }
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
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 above is what stop you playing a card of the same type as the previous.
+
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:
 +
 
 +
<syntaxhighlight lang=c#>
 +
if (Hand.GetCardDescriptionAt(cardChoice - 1)[0] != Sequence.GetCardDescriptionAt(Sequence.GetNumberOfCards() - 1)[0])
 +
                {
 +
                    Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(cardChoice - 1));
 +
                    GetCardFromDeck(cardChoice);
 +
                }
 +
</syntaxhighlight>
  
 
=What you need to do=
 
=What you need to do=
* Add an else condition to the if statement.
+
* Add an else condition to the second if statement.

Latest revision as of 14:00, 22 December 2021

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.