2022 - Add a joker card

From TRCCompSci - AQA Computer Science
Revision as of 11:14, 23 December 2021 by Admin (talk | contribs) (Process Method Of JokerCard)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Task

Create a new card child class for a Joker card.

If a player draws a Joker card they are able to decide what type of card they want it to be, and will also be able to choose the kit it belongs to.

There should be two Joker cards in the deck. These should be added like the difficulty cards, and should be added after the user draws their hand.

What you need to do

JokerCard SubClass

  • Create a subclass of Card called JokerCard (look at ToolCard & copy the whole class).
  • I have adapted the two constructor methods so they are now like this:
        public JokerCard() : base()
        {
            ToolType = "Jok";
            Kit = "";
        }

        public void Init(string t, string k)
        {
            ToolType = t;
            Kit = k;
            SetScore();
        }

Process Method Of JokerCard

  • Now add a Process method to the JokerCard class:
public override void Process(CardCollection deck, CardCollection discard, CardCollection hand, CardCollection sequence, Lock currentLock, string choice, int cardChoice)
{
           
}
  • Now inside the new process method:
    • Display a message to enter the card type P, K, or F
    • Get the user input and store as t
    • Display a message enter the kit number a, b, or c
    • Get the user input and store as k
    • call the Init() method above with the 2 user inputs (t & k)

Create & Add JokerCards

  • Look at how DifficultyCards are added to the deck (find the SetupGame & AddDifficultyCardsToDeck methods).
  • Copy the method AddDifficultyCardsToDeck, rename it to AddJokerCardsToDeck.
  • in your new AddJokerCardsToDeck, make sure you only create 2 (the original will create 5).
  • Add the code to create 2 JokerCards, and add them to the deck before they are shuffled.

Using A JokerCard

  • Find the PlayCardToSequence method.
  • Before the first if statement create a new if statement to check if the card played is a JokerCard:
 if(Hand.GetCardDescriptionAt(cardChoice - 1).Contains("Jok"))
 {
                Card temp = Hand.RemoveCard(Hand.GetCardNumberAt(cardChoice - 1)); //remove the joker card from the hand
                temp.Process(Deck, Discard, Hand, Sequence, CurrentLock, "", cardChoice); //run the process method to set the new type & kit
                Sequence.AddCard(temp); //add the updated card to the sequence
                GetCardFromDeck(cardChoice); //draw a new card

}
  • Then create an else to this if statement
  • Move the following code into the else:
                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);
                }