Difference between revisions of "2022 - Add a joker card"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Getting Dealt A RetrieveCard)
(Process Method Of JokerCard)
 
(7 intermediate revisions by the same user not shown)
Line 24: Line 24:
 
         }
 
         }
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
==Process Method Of JokerCard==
 +
* Now add a Process method to the JokerCard class:
 +
 +
<syntaxhighlight lang=c#>
 +
public override void Process(CardCollection deck, CardCollection discard, CardCollection hand, CardCollection sequence, Lock currentLock, string choice, int cardChoice)
 +
{
 +
         
 +
}
 +
</syntaxhighlight>
 +
 +
* 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==
 
==Create & Add JokerCards==
Line 30: Line 47:
 
* in your new AddJokerCardsToDeck, make sure you only create 2 (the original will create 5).
 
* 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.
 
* Add the code to create 2 JokerCards, and add them to the deck before they are shuffled.
==Getting Dealt A JokerCard==
+
==Using A JokerCard==
* Find the GetCardFromDeck method, look at the 'if (Deck.GetCardDescriptionAt(0) == "Dif")'.
+
* Find the PlayCardToSequence method.
* You need to add before or after this entire if statement 'if (Deck.GetCardDescriptionAt(0) == "Jok"){}'
+
* Before the first if statement create a new if statement to check if the card played is a JokerCard:
* Add the code to the new if statement that will run the process method of the JokerCard, ie:
 
 
<syntaxhighlight lang=c#>
 
<syntaxhighlight lang=c#>
                 if (Deck.GetCardDescriptionAt(0) == "Jok")
+
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
 +
 
 +
}
 +
</syntaxhighlight>
 +
* Then create an else to this if statement
 +
* Move the following code into the else:
 +
<syntaxhighlight lang=c#>
 +
                 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
 
                 {
 
                 {
                     Card CurrentCard = Deck.RemoveCard(Deck.GetCardNumberAt(0));
+
                     Score += MoveCard(Hand, Sequence, Hand.GetCardNumberAt(cardChoice - 1));
                     Hand.AddCard(CurrentCard);
+
                     GetCardFromDeck(cardChoice);
                    CurrentCard.Process(Deck, Discard, Hand, Sequence, CurrentLock, "", cardChoice);
 
 
                 }
 
                 }
 
</syntaxhighlight>
 
</syntaxhighlight>
 
==Process Method Of JokerCard==
 
* Now add the code to the Process method of the RetrieveCard class:
 

Latest revision as of 12:14, 23 December 2021

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);
                }