I wrote this code that displays a card that could be used in a card game in the future.
I got the stuff on making colors here:
Wonderful Tutorial
What do you think?Code:#include <iostream.h>
#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()
{
string cardtype;
string cardnum;
cardtype = CardType();
cout<<"\n\n\n";
cardnum = CardNum();
DrawCard(cardtype, cardnum);
cin.get();
return 0;
}
void Black (string cardtype)
{
HANDLE hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hOut,
FW | BB);
cout << " ";
if (cardtype == "S" || cardtype == "C") {
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);
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;
srand(time(NULL));
temp = (rand() % (max - min + 1) + min);
switch (temp) {
case 1:
card = "D";
break;
case 2:
card = "H";
break;
case 3:
card = "S";
break;
case 4:
card = "C";
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 = "T";
break;
case 11:
card2 = "J";
break;
case 12:
card2 = "Q";
break;
case 13:
card2 = "K";
break;
}
return card2;
}