It's very basic, I've made a few changes:
Should show card symbols instead of H,D,C,S
Should use 10 instead of T
srand should only be called once. Move to main()
Now to make this usable, you need a way to draw more than one card on a line, I'll leave that for you to do.
Also, after every draw you should return the colors back to the default so that any text output is "normal".
Code:
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <string>
#include <ctime>
#define FW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
#define BW BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |BACKGROUND_INTENSITY
#define FR FOREGROUND_RED | FOREGROUND_INTENSITY
#define BB 0
using namespace std;
void Black (string cardtype);
void DrawCard (string cardtype, string cardnum);
string CardType ();
string CardNum ();
int main()
{
srand(time(NULL)); // This should only be called once so moved to main()
string cardtype;
string cardnum;
cardtype = CardType();
cout<<"\n\n\n";
cardnum = CardNum();
DrawCard(cardtype, "10");
cin.get();
return 0;
}
void Black (string cardtype)
{
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut, FW | BB);
cout << " ";
if (cardtype[0]>4)
{
SetConsoleTextAttribute(hOut, BB);
SetConsoleTextAttribute(hOut, BW);
}
else
{
SetConsoleTextAttribute(hOut,FR | BW);
}
}
void DrawCard(string cardtype, string cardnum)
{
Black(cardtype);
cout << " " << endl;
Black(cardtype);
cout << " " << endl;
Black(cardtype);
// handle the 2 digit 10
if(cardnum == "10" ) cout << " " << cardnum << " " << endl;
else cout << " " << cardnum << " " << endl;
Black(cardtype);
cout << " " << endl;
Black(cardtype);
cout << " " << cardtype << " " << endl;
Black(cardtype);
cout << " " << endl;
Black(cardtype);
cout << " " << endl;
}
string CardType ()
{
int max = 4;
int min = 1;
int temp;
string card;
temp = (rand() % (max - min + 1) + min);
switch (temp)
{
case 1:
card = (char)4; // Diamond
break;
case 2:
card = (char)3; //Heart
break;
case 3:
card = (char)6; //Spade
break;
case 4:
card = (char)5; //Club
break;
}
return card;
}
string CardNum ()
{
int max2 = 13;
int min2 = 1;
int temp2;
string card2;
srand(time(NULL));
temp2 = (rand() % (max2 - min2 + 1) + min2);
switch (temp2)
{
case 1:
card2 = "A";
break;
case 2:
card2 = "2";
break;
case 3:
card2 = "3";
break;
case 4:
card2 = "4";
break;
case 5:
card2 = "5";
break;
case 6:
card2 = "6";
break;
case 7:
card2 = "7";
break;
case 8:
card2 = "8";
break;
case 9:
card2 = "9";
break;
case 10:
card2 = "10"; // Real cards show 10, not T
break;
case 11:
card2 = "J";
break;
case 12:
card2 = "Q";
break;
case 13:
card2 = "K";
break;
}
return card2;
}