Difference between revisions of "2022 - Card"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Created page with "<syntaxhighlight lang=c#> class Card { protected int CardNumber, Score; protected static int NextCardNumber = 1; public Card() {...")
 
Line 1: Line 1:
 +
This is the base class for all cards.
 +
 +
=The Code=
 
<syntaxhighlight lang=c#>
 
<syntaxhighlight lang=c#>
 
class Card
 
class Card
Line 40: Line 43:
 
         }
 
         }
 
     }
 
     }
 +
</syntaxhighlight>
 +
 +
=The Constructor Method=
 +
Remember the constructor method of a class is a public method called exactly the same name as the class. So in this case:
 +
<syntaxhighlight lang=c#>
 +
        public Card()
 +
        {
 +
            CardNumber = NextCardNumber;
 +
            NextCardNumber += 1;
 +
            Score = 0;
 +
        }
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 13:45, 22 December 2021

This is the base class for all cards.

The Code

class Card
    {
        protected int CardNumber, Score;
        protected static int NextCardNumber = 1;

        public Card()
        {
            CardNumber = NextCardNumber;
            NextCardNumber += 1;
            Score = 0;
        }

        public virtual int GetScore()
        {
            return Score;
        }

        public virtual void Process(CardCollection deck, CardCollection discard,
            CardCollection hand, CardCollection sequence, Lock currentLock,
            string choice, int cardChoice)
        {
        }

        public virtual int GetCardNumber()
        {
            return CardNumber;
        }

        public virtual string GetDescription()
        {
            if (CardNumber < 10)
            {
                return " " + CardNumber.ToString();
            }
            else
            {
                return CardNumber.ToString();
            }
        }
    }

The Constructor Method

Remember the constructor method of a class is a public method called exactly the same name as the class. So in this case:

        public Card()
        {
            CardNumber = NextCardNumber;
            NextCardNumber += 1;
            Score = 0;
        }