C++ Source Code - nathanlamont91.files.wordpress.com file · Web viewC++ Source Code. #include ...
Transcript of C++ Source Code - nathanlamont91.files.wordpress.com file · Web viewC++ Source Code. #include ...
C++ Source Code#include <iostream>#include <conio.h>#include <windows.h>#include <ctime>#include <cstdlib>
using namespace std;
#define Spade 06#define Club 05#define Diamond 04#define Heart 03enum Suits {HEART, DIAMOND, CLUB, SPADE};
struct Card{
int CardValue;Suits CardSuit;int CardWorth;
};
const int NumberOfCards = 52;const int CardsPerSuit = 13;Card Pack[NumberOfCards];Card CardTempSlot;int CardIndex; //For setting up pack.
void AboutMenu();void HelpMenu();void SetUpPack();void PlayGame();void ShufflePack();void DealHand(int Position, int x, int y);void PlayerStickTwistBust(int Position, int x, int y);void DealerStickTwistBust(int Position, int x, int y);void WhoWins();void PlayAgainOption();void SetFontAttributes();void PlayersHandAceCheck(); //Checks players hand for an ace when score > 21.void DealersHandAceCheck();//Checks dealers hand for an ace when score > 21.void DisplayPlayersScore();void DisplayDealersScore();void InGameOptions();
void DisplayCard(int Position, int x, int y);char DisplayCardValue(int CardValue);char DisplayCardSuit(int Position);void SetSuitIconColour(Suits CardSuit);
void SetTextColour(int Colour);void GoToXY(int x, int y);void ClearScreen();void SetWindow(int x, int y); //Change the size of the console window.void ClearLine();
int RandomNum1;int RandomNum2;int Shuffle;
int Position;int AddPosition = 0; //Needed this to save position of the card last used in pack.
//Position would revert back to 0 at points if I never stated 'AddPosition = Position" and then before the next card is drawn 'Position = AddPosition'.int PlayerScore = 0;int DealerScore = 0;int XSpacing = 13;int YSpacing = 22;//Spacing between cards on screen.int PlayerWinCondition; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.int DealerWinCondition; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.int CardCounter; //Counts for five card trick or pontoon.
int PlayersHand[5]; //My array for what the players hand contains.int HandIndex = 0; //First card in players' hand is placed in 0, second card in 1, ++.int DealersHand[5]; //Exact same concept as PlayersHand.int DHandIndex = 0; //^^^^^^^^^^^^
void main() //no need for int main. I previously had void MainMenu but realised that I could have void main which can be called from within other voids unlike int main.{
SetWindow(100, 50); //Larger window than usual, more aesthetically pleasing.
SetFontAttributes(); //Calls to change [ALL] font size.int MenuChoice;
// This is all of the menu visuals.ClearScreen();SetUpPack(); //Need to set up pack sooner that I would have as I print
cards to show Pontoon.DisplayCard(12, 35, 6); //Shows King Hearts.DisplayCard(39, 48, 6); //Shows Ace Spades.GoToXY(40, 1);cout << "Nathan's Pontoon" << endl;GoToXY(41, 20);cout << "1. Play Game" << endl;GoToXY(41, 21);cout << "2. About" << endl;GoToXY(41, 22);cout << "3. Help" << endl;GoToXY(41, 23);cout << "4. Quit" << endl;
// End of visuals.
cin >> MenuChoice;
if (MenuChoice == 1){SetUpPack();ShufflePack();ClearScreen();PlayGame();}
else if (MenuChoice == 2){
AboutMenu();}
else if (MenuChoice == 3){
HelpMenu();}
else if (MenuChoice == 4){
exit(0);}
}//End of main().
void PlayGame(){
DealHand(Position, 17, 8);PlayerStickTwistBust(Position, 30, 30);DealerStickTwistBust(Position, 30, 8);WhoWins();PlayAgainOption();
}//End of PlayGame().
void AboutMenu(){
ClearScreen();
int Input = 0;
GoToXY(40, 1);cout << "About Menu" << endl;
GoToXY(1, 3);cout << "Nathan Lamont - S14002354 - Glyndwr University." << endl <<
endl;
//Referencing the code I used to change font size.cout << endl << "'Change Font Size' Code: Credited to Yi Feng Li." <<
endl;cout << " Available at URL Link:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/192c888a-2994-48aa" << endl;
cout << " -bb17-ec95f03535b0/how-to-use-graphic-class-in-visual-c-console-application?forum=vcgeneral" << endl << endl;
cout << " Things that I have learnt" << endl;cout << " The main and most simple mistake I made was by writing the
same code out four times which done" << endl;cout << " the exact same function. This was drawing a card/twist. If I
created this game or if I had more" << endl;cout << " time, I would create a seperate function for 'twist' and call
that everytime." << endl;cout << " I have also realised that the arrays I created, PlayersHand
and DealersHand. I could have" << endl;cout << " made better use of them, for example I could have managed
scores using the arrays too" << endl;cout << " rather than have created spereate functions as well as many
other manipulations." << endl << endl;
cout << " Problems with my game" << endl;cout << " When two ACEs are dealt to the player or dealer, both are
reduced to hold the value 1 rather" << endl;cout << " than only one Ace being valued 1 and the other to stay at 11."
<< endl;cout << " The other problem is also with the ACEs. If There is an ACE in
one of the first 3 slots of" << endl;cout << " either the 'PlayersHand' or 'DealersHand' the values of the
fourth and fith card in the hand" << endl;cout << " will not be stored into the array." << endl;
GoToXY(45, 48);cout << "0 = Main Menu";
cin >> Input;
if(Input == 0){
main();}
else if(Input != 0){
cout << "Invalid Input. Try Again.";}
}//End of AboutMenu().
void HelpMenu(){
ClearScreen();
int Input = 0;
GoToXY(40, 1);cout << "Rules of Pontoon" << endl << endl;
cout << " What the player is trying to do is assemble a better hand than the dealer - which is to say, cards" << endl;
cout << " totalling as close to 21 as possible without going over. Aces count as a Score of 1 or 11, as the" << endl;
cout << " holder prefers; the 10 and court cards are worth 10; the rest have face value. The best possible" << endl;
cout << " hand is a two-card 21 (pontoon): this can consist of an ace plus a royal card or 10. Next is a" << endl;
cout << " five-card trick: five cards of any total value under or equal to 21." << endl << endl;
cout << " The player has several choices; if you have a pontoon, turn your ace face up and pass the turn." << endl;
cout << " Otherwise, you may: Stick: Ask for no more cards, because you are happy with the total (although" << endl;
cout << " you cannot stick on less than 15). Twist: Ask the dealer to turn over the next card face up. You" << endl;
cout << " can do this up to three times, or until you are bust. Now the dealer turns over her cards, and" << endl;
cout << " sticks or twists until satisfied (must twist if total is below 17). Now, the result is given. In" << endl;
cout << " the event of a tie,the dealer wins, so a dealer's pontoon is unbeatable. The dealer also wins if" << endl;
cout << " both the player and dealer bust." << endl << endl;
cout << " The pack of cards is shuffled after the first 40 cards have been used." << endl;
GoToXY(45, 48);cout << "0 = Main Menu";
cin >> Input;
if(Input == 0){
main();}
else if(Input != 0){
cout << "Invalid Input. Try Again.";}
}//End of HelpMenu().
void ShufflePack(){
unsigned seed = time(0);srand(seed);
for (int Shuffle = 0; Shuffle < 100; Shuffle++){
//Modulus 52 gives values 0-51.int RandomNum1 = rand() % 52;int RandomNum2 = rand() % 52;
//Swapping cards around.CardTempSlot = Pack[RandomNum1];Pack[RandomNum1] = Pack[RandomNum2];Pack[RandomNum2] = CardTempSlot;
}}//End of ShufflePack().
void DealHand(int Position, int x, int y){
Position = AddPosition;HandIndex = 0; //Resetting it from last hand otherwise the values will
not be stored correctly.DHandIndex = 0;// ^^^^^.
//Displaying Dealer's Hand. First Card. [Second shouldn't be seen by the player].
Position = Position; //Card last drawn in deck, keep track so it knows when to shuffle.
DisplayCard(Position, 17, 8);DealerScore = DealerScore + Pack[Position].CardWorth;DealersHand[DHandIndex] = Pack[Position].CardWorth; //Add card(worth of)
to the array DealersHand.
//Displaying Player's Hand. First Card.Position = Position + 1; //Card last drawn in deck, keep track so it
knows when to shuffle.
DisplayCard(Position, x, y+YSpacing);PlayerScore = PlayerScore + Pack[Position].CardWorth;PlayersHand[HandIndex] = Pack[Position].CardWorth; //Add card(worth of)
to the array PlayersHand.
//Displaying Player's Second Card.Position = Position + 1; //Card last drawn in deck, keep track so it
knows when to shuffle.DisplayCard(Position, x+XSpacing, y+YSpacing);PlayerScore = PlayerScore + Pack[Position].CardWorth;PlayersHand[HandIndex+1] = Pack[Position].CardWorth; //Add card(worth
of) to the array PlayersHand.HandIndex = HandIndex + 1;
PlayersHandAceCheck(); //Checking in case Player was dealt two ACEs.
AddPosition = Position;}//End of DealHand().
void PlayerStickTwistBust(int Position, int x, int y){
int Input = 0; //Player's choice when asked what to do.
Position = AddPosition;
CardCounter = 2; //To count for five card trick.
GoToXY(40, 1);cout << "Nathan's Pontoon";GoToXY(2, 30);cout << "Players Hand";GoToXY(2, 8);cout << "Dealers Hand";DisplayPlayersScore();InGameOptions();
GoToXY(25, 25);cout << "Would You Like To Stick Or Twist?";
while(PlayerScore < 21 && Input != 2){
cin >> Input;
if(Input == 1){
HandIndex = HandIndex + 1;Position = Position + 1; //Card last drawn in deck,
keep track so it knows when to shuffle.DisplayCard(Position, x+XSpacing, y);x = x+XSpacing, y;PlayerScore = PlayerScore + Pack[Position].CardWorth;GoToXY(40, 30);PlayersHand[HandIndex] = Pack[Position].CardWorth;
//Add card(worth of) to the array PlayersHand.CardCounter = CardCounter + 1;DisplayPlayersScore();PlayersHandAceCheck();
if(CardCounter == 5)
{Input = 2;
}}
while(Input == 2 && PlayerScore < 15){
GoToXY(25, 25);cout << "You Can Not Stick With A Score Below 15.
Please Twist.";
cin >> Input;
GoToXY(25, 25);ClearLine();
if(Input == 1){
HandIndex = HandIndex + 1;Position = Position + 1;DisplayCard(Position, x+XSpacing, y);x = x+XSpacing, y;PlayerScore = PlayerScore +
Pack[Position].CardWorth;GoToXY(40, 40);PlayersHand[HandIndex] =
Pack[Position].CardWorth;CardCounter = CardCounter + 1;DisplayPlayersScore();PlayersHandAceCheck();
if(CardCounter == 5){
Input = 2;}
}
}
if(Input == 0) //To return to the main menu.{
PlayerScore = 0; //Resetting Scores In CaseDealerScore = 0; //They Play Again.main();
}
else if(Input > 2){
GoToXY(40, 45);cout << "Invalid Input. Try Again.";
}}
GoToXY(30,28);if(PlayerScore == 21 && CardCounter == 2){
cout << "Player Got Pontoon!";
PlayerWinCondition = 1;}
else if(PlayerScore < 22 && CardCounter == 5){
cout << "Player Got A Five Card Trick!";
PlayerWinCondition = 2;}
else if(PlayerScore < 22 && CardCounter != 5){
cout << "Player Has Stuck On " << PlayerScore << ".";
PlayerWinCondition = 3;}
else if(PlayerScore > 21){
cout << "Player Has Bust On " << PlayerScore << ".";
PlayerWinCondition = 4; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.
}
AddPosition = Position; //This saves the Position of last card drawn.(Position of current card would't save, it would draw [0] when player twists).
GoToXY(0, 25);ClearLine(); //Deletes "Stick Or Twist" message.GoToXY(25, 25);cout << "Dealers Turn. Press Any Key To Continue"; //Prints new message
getch();}//End of PlayerStickTwistBust().
void DealerStickTwistBust(int Position, int x, int y){
Position = AddPosition;
//Displaying Dealers Second Card. [Now that player has taken their turn].Position = Position + 1; //Card last drawn in deck, keep track so it
knows when to shuffle.DisplayCard(Position, 30, 8); //Although I could state the coords of
each card that I want to display seperately, this is a more dynamic way, saves time and can't be wrongly calculated.
DealerScore = DealerScore + Pack[Position].CardWorth;DealersHand[DHandIndex] = Pack[Position].CardWorth; //Add card(worth of)
to the array DealersHand.DHandIndex = DHandIndex + 1;DisplayDealersScore();
DealersHandAceCheck(); //Just in case the dealer was dealt two ACEs.
CardCounter = 2; //To count for five card trick. [Resetting it here after player has had their turn].
while(DealerScore < 17) //Dealer has to twist when below 17.{
DHandIndex = DHandIndex + 1;Position = Position + 1;DisplayCard(Position, x+XSpacing, y);
x = x+XSpacing, y;DealerScore = DealerScore + Pack[Position].CardWorth;DealersHand[DHandIndex] = Pack[Position].CardWorth; //Add
card(worth of) to the array DealersHand.CardCounter = CardCounter + 1;DisplayDealersScore();DealersHandAceCheck();
if(CardCounter == 5) //Test for five card trick. If true, end loop.
{break;
}}
GoToXY(30, 21);if(DealerScore > 21){
cout << "Dealer Has Bust On " << DealerScore << ".";
DealerWinCondition = 4; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.
}
else if(DealerScore == 21 && CardCounter == 2){
cout << "Dealer Got Pontoon!";
DealerWinCondition = 1; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.
}
else if(CardCounter == 5){
cout << "Dealer Got A Five Card Trick!";
DealerWinCondition = 2; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.
}
else if(CardCounter != 5){
cout << "Dealer Has Stuck On " << DealerScore << ".";
DealerWinCondition = 3; //1 = Pontoon. 2 = Five card trick. 3 = Any other legal score. 4 = Bust.
}
AddPosition = Position + 1; //When playing another hand, without the "+1" the last card drawn would be the first card dealt next hand.}//End of DealerStickTwistBust().
void WhoWins(){
GoToXY(25, 25);if(PlayerWinCondition < DealerWinCondition) //Pontoon > five card tick >
any other legal score > bust.{
cout << "Player Wins! - Would You Like To Play Again?";}
else if(DealerWinCondition == 1) //Dealer always wins with Pontoon.{
cout << "Dealer Wins! - Would You Like To Play Again?";}
else if(DealerWinCondition < PlayerWinCondition) //Pontoon > five card tick > any other legal score > bust.
{cout << "Dealer Wins! - Would You Like To Play Again?";
}
else if(DealerWinCondition == 2 && PlayerWinCondition == 2) //Any tie is a win for the dealer.
{cout << "Dealer Wins! - Would You Like To Play Again?";
}
else if(DealerWinCondition == 4 && PlayerWinCondition == 4) //Any tie is a win for the dealer.
{cout << "Dealer Wins! - Would You Like To Play Again?";
}
else if(DealerWinCondition == 3 && PlayerWinCondition == 3){
if(DealerScore >= PlayerScore){cout << "Dealer Wins! - Would You Like To Play Again?";}
else if(DealerScore < PlayerScore){cout << "Player Wins! - Would You Like To Play Again?";}
}
}//End of WhoWins().
void PlayAgainOption(){int PlayerChoice = 0; //Player option whether or not to play again.
GoToXY(12, 48);cout << "1. Play Another Hand ";cout << "2. Return To The Main Menu ";cout << "3. Exit Application";
cin >> PlayerChoice;
if(PlayerChoice > 3) //For invalid input, loop until a valid input is entered.
{while(PlayerChoice > 3){
GoToXY(40, 45);cout << "Invalid Input. Try Again." << endl;cin >> PlayerChoice;
}}
//I used 'if' instead of 'if else' so that if the PlayerChoice > 3 and then next time PlayerChocie < 3, then this statement would be considered as well as the prior statement.
if(PlayerChoice == 1) //Does the pack need shuffling?{
if (AddPosition > 40) //If card 41 has been used, only a maximum of 9 cards are left undealt, this may not be enough for the player's and dealer's hands.
{ShufflePack();AddPosition = 0;
}
PlayerScore = 0; //Resetting Scores, ReadyDealerScore = 0; //For The Next Hand.ClearScreen();PlayGame();
}
else if(PlayerChoice == 2){
PlayerScore = 0; //Although this option takes the player back to the main menu
DealerScore = 0; //We reset the scores in case they play again.
main();}
else if(PlayerChoice == 3){
exit(0);}
}//End of PlayAgainOption().
void PlayersHandAceCheck(){
if(PlayerScore > 21){
for(HandIndex = 0; HandIndex < 5; HandIndex++) //When players score >21, it searches player's current hand.
{if(PlayersHand[HandIndex] == 11) //Searching to see if there
is an ace.{
PlayersHand[HandIndex] = 1; //When ace is found, changes the worth of that ace to 1.
PlayerScore = PlayerScore - 10; //Also takes 10 from players score as ace worth decreases by 10.
DisplayPlayersScore();}
}}
}
void DealersHandAceCheck(){
if(DealerScore > 21){
for(DHandIndex = 0; DHandIndex < 5; DHandIndex++) //When dealers score >21, it searches dealer's current hand.
{if(DealersHand[DHandIndex] == 11) //Searching to see if
there is an ace.{
if(DealerScore > 21){DealersHand[DHandIndex] = 1; //When ace is found,
changes the worth of that ace to 1.DealerScore = DealerScore - 10; //Also takes 10 from
dealers score as ace worth decreases by 10.DisplayDealersScore();}
}
}}
}
void DisplayPlayersScore(){
GoToXY(3, 35);cout << "Score: " << PlayerScore << endl << endl;
}//End of DisplayPlayersScore().
void DisplayDealersScore(){
GoToXY(3, 13);cout << "Score: " << DealerScore;
}//End of DisplayDealersScore().
void InGameOptions(){
#define Strip 220
GoToXY(1, 46);for(int l = 0; l < 98; l++){
cout << char(Strip);}
GoToXY(25, 48);cout << "1 = Twist";GoToXY(45, 48);cout << "2 = Stick";GoToXY(65, 48);cout << "0 = Main Menu";
}//End of InGameOptions().
//Created ClearLine to clear outdated messages off screen.void ClearLine(){
for(int p = 0; p < 100; p++){
cout << " ";}
}//End of ClearLine().
//Text & Background Colour Handler.void SetTextColour(int Colour){HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(hConsole, Colour);}//End of Text & Background Colour Handler().
void SetFontAttributes() //I took this from the internet just like i did the window size however, it took me around 4 hours to find something this useful!{ HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Obtain the Console handle
PCONSOLE_FONT_INFOEX lpConsoleCurrentFontEx = new CONSOLE_FONT_INFOEX() ;
//Sets the size of the CONSOLE_FONT_INFOEX(memory).lpConsoleCurrentFontEx->cbSize = sizeof(CONSOLE_FONT_INFOEX);
//Retrieves the current fonts values.GetCurrentConsoleFontEx(hConsole,0,lpConsoleCurrentFontEx); //Set size to be 8x18, the default size is 8x16lpConsoleCurrentFontEx->dwFontSize.X = 8;lpConsoleCurrentFontEx->dwFontSize.Y = 18; //Submits the new, updated font settings.SetCurrentConsoleFontEx(hConsole,0,lpConsoleCurrentFontEx);}//End of SetFontAttributes().
void ClearScreen() //To create a clear green screen.{
GoToXY(0,0);
for (int Line = 0; Line < 50; Line++) //50 to suit the width of the window.
{for (int Bit = 0; Bit < 100; Bit++) //100 to suit the length of
the buffer.{
SetTextColour(47); //Green screen with white text.cout << " ";
}cout << endl;
}
//GoToXY(0,0);}//End of ClearScreen().
//Cursor Position Handler.void GoToXY(int x, int y){
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);_COORD Position;Position.X = x;Position.Y = y;SetConsoleCursorPosition(hConsole, Position);
}//End of Cursor Position Handler().
void SetWindow(int Width, int Height) //Sets the size of the console window. TAKEN FROM THE INTERNET, I used a link you have given us in an Adobe file, I hope that is allowed.{
_COORD coord; coord.X = Width; coord.Y = Height;
_SMALL_RECT Rect; Rect.Top = 0; Rect.Left = 0; Rect.Bottom = Height - 1; Rect.Right = Width - 1;
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleScreenBufferSize(Handle, coord);// Set Buffer Size SetConsoleWindowInfo(Handle, TRUE, &Rect);// Set Window Size
}
void SetUpPack(){//Setting up Hearts.
for (CardIndex = 0; CardIndex < CardsPerSuit; CardIndex++){
Pack[CardIndex].CardValue = CardIndex +1;Pack[CardIndex].CardSuit = HEART;Pack[CardIndex].CardWorth = CardIndex +1;
}Pack[0].CardWorth = 11;Pack[10].CardWorth = 10;Pack[11].CardWorth = 10;Pack[12].CardWorth = 10;
//Setting up Diamonds.for (CardIndex = 13; CardIndex < CardsPerSuit+13; CardIndex++)
{Pack[CardIndex].CardValue = CardIndex -12;Pack[CardIndex].CardSuit = DIAMOND;Pack[CardIndex].CardWorth = CardIndex -12;
}Pack[13].CardWorth = 11;Pack[23].CardWorth = 10;Pack[24].CardWorth = 10;Pack[25].CardWorth = 10;
//Setting up Club.for (CardIndex = 26; CardIndex < CardsPerSuit+26; CardIndex++)
{Pack[CardIndex].CardValue = CardIndex -25;Pack[CardIndex].CardSuit = CLUB;Pack[CardIndex].CardWorth = CardIndex -25;
}Pack[26].CardWorth = 11;Pack[36].CardWorth = 10;Pack[37].CardWorth = 10;Pack[38].CardWorth = 10;
//Setting up Spades.for (CardIndex = 39; CardIndex < CardsPerSuit+39; CardIndex++)
{Pack[CardIndex].CardValue = CardIndex -38;Pack[CardIndex].CardSuit = SPADE;Pack[CardIndex].CardWorth = CardIndex -38;
}Pack[39].CardWorth = 11;Pack[49].CardWorth = 10;Pack[50].CardWorth = 10;Pack[51].CardWorth = 10;
}//End of SetUpPack().
void DisplayCard(int Position, int x, int y){#define TopLeftCorner 201#define BottomRightCorner 188#define TopRightCorner 187#define BottomLeftCorner 200#define VerticalLine 186#define HorizontalLine 205
int Length;SetTextColour(240);
//Top of the card.GoToXY(x,y);cout << char(TopLeftCorner);
for(int TextBlit = 0; TextBlit < 10; TextBlit++){
cout << char(HorizontalLine);}
cout << char(TopRightCorner) << endl;
//Both sides of the card.for(Length = 0; Length < 10; Length++){
GoToXY(x,y+1+Length);cout << char(VerticalLine);
for(int TextBlit = 0; TextBlit < 10; TextBlit++){
cout << " ";}
cout << char(VerticalLine) << endl;}
//Bottom of the card.GoToXY(x,y+1+Length);cout << char(BottomLeftCorner);
for(int TextBlit = 0; TextBlit < 10; TextBlit++){
cout << char(HorizontalLine);}
cout << char(BottomRightCorner);
//Display the suit and value of a card(Top left).SetTextColour(240);GoToXY(x+2,y+1);cout << DisplayCardValue(Pack[Position].CardValue);SetSuitIconColour(Pack[Position].CardSuit);cout << DisplayCardSuit(Position);SetTextColour(47);
//Display the suit and value of a card(Bottom right).GoToXY(x+8,y+Length);SetTextColour(240);cout << DisplayCardValue(Pack[Position].CardValue);SetSuitIconColour(Pack[Position].CardSuit);cout << DisplayCardSuit(Position);SetTextColour(47);
}//End of DisplayCard(int Position, int x, int y).
char DisplayCardValue(int CardValue){
if (CardValue == 1){
return 'A';}
else if (CardValue == 10){
return 'T';}
else if (CardValue == 11){
return 'J';}
else if (CardValue == 12){
return 'Q';}
else if (CardValue == 13){
return 'K';}
else{
return char(CardValue +48); //Returns a character based on ASCII code e.g. 5 hearts == 5+48=53=ASCII code for 5
}}//End of DisplayCardValue().
char DisplayCardSuit(int CardIndex){
if (Pack[CardIndex].CardSuit == HEART){
return char (Heart);}
else if (Pack[CardIndex].CardSuit == DIAMOND){
return char (Diamond);}
else if (Pack[CardIndex].CardSuit == CLUB){
return char (Club);}
else if (Pack[CardIndex].CardSuit == SPADE){
return char (Spade);}
}//End of DisplayCardSuit().
void SetSuitIconColour(Suits CardSuit){
if (CardSuit == HEART){
SetTextColour(252); //Sets red text with white background.}
if (CardSuit == DIAMOND){
SetTextColour(252); //Sets red text with white background.}
if (CardSuit == CLUB){
SetTextColour(240); //Sets black text with white background.}
if (CardSuit == SPADE){
SetTextColour(240); //Sets black text with white background.}
}
//End of SetSuitIconColour().