Difference between revisions of "2022 - DifficultyCard"
(Created page with "=The Code= <syntaxhighlight lang=c#> class DifficultyCard : Card { protected string CardType; public DifficultyCard() : base() {...") |
|||
Line 55: | Line 55: | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | =New Variables= | ||
+ | The DifficultyCard class declares a protected variable called 'CardType' as a string. Protected means it will be available in any subclass of DifficultyCard. | ||
+ | |||
+ | =Constructors= | ||
+ | The DifficultyCard class has 2 constructors, again this is okay as long as they have different parameters: | ||
+ | |||
+ | <syntaxhighlight lang=c#> | ||
+ | public DifficultyCard() | ||
+ | : base() | ||
+ | { | ||
+ | CardType = "Dif"; | ||
+ | } | ||
+ | |||
+ | public DifficultyCard(int cardNo) | ||
+ | { | ||
+ | CardType = "Dif"; | ||
+ | CardNumber = cardNo; | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | =Process Method= |
Revision as of 11:39, 23 December 2021
The Code
class DifficultyCard : Card
{
protected string CardType;
public DifficultyCard()
: base()
{
CardType = "Dif";
}
public DifficultyCard(int cardNo)
{
CardType = "Dif";
CardNumber = cardNo;
}
public override string GetDescription()
{
return CardType;
}
public override void Process(CardCollection deck, CardCollection discard, CardCollection hand, CardCollection sequence, Lock currentLock, string choice, int cardChoice)
{
int ChoiceAsInteger;
if (int.TryParse(choice, out ChoiceAsInteger))
{
if (ChoiceAsInteger >= 1 && ChoiceAsInteger <= 5)
{
if (ChoiceAsInteger >= cardChoice)
{
ChoiceAsInteger -= 1;
}
if (ChoiceAsInteger > 0)
{
ChoiceAsInteger -= 1;
}
if (hand.GetCardDescriptionAt(ChoiceAsInteger)[0] == 'K')
{
Card CardToMove = hand.RemoveCard(hand.GetCardNumberAt(ChoiceAsInteger));
discard.AddCard(CardToMove);
return;
}
}
}
int Count = 0;
while (Count < 5 && deck.GetNumberOfCards() > 0)
{
Card CardToMove = deck.RemoveCard(deck.GetCardNumberAt(0));
discard.AddCard(CardToMove);
Count += 1;
}
}
}
New Variables
The DifficultyCard class declares a protected variable called 'CardType' as a string. Protected means it will be available in any subclass of DifficultyCard.
Constructors
The DifficultyCard class has 2 constructors, again this is okay as long as they have different parameters:
public DifficultyCard()
: base()
{
CardType = "Dif";
}
public DifficultyCard(int cardNo)
{
CardType = "Dif";
CardNumber = cardNo;
}