1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <windows.h>
struct Cards
{
enum Suit {
DIAMOND, CLUB, HEART, SPADE
};
enum Card {
ZERO , // ?
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX ,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING
};
// ...
Suit suit;
Card card; // ?
// ... etc..
};
std::ostream& operator<< ( std::ostream& os, const Cards& cards )
{
const char* CARDS[] = {
"0", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"
};
const char* SUITS[] = {
"D", "C", "H", "S"
};
const WORD COLORS[] = {
// background -- foreground
0x01, // Diamond -- Blue on Black
0x02, // Club -- Green
0x03, // Heart -- Aqua
0x04 // Spade -- Red
};
// Get handle to the console
HANDLE hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if( hStdOut ) { // if valid handle
// change ConsoleTextAttribute
SetConsoleTextAttribute( hStdOut, COLORS[cards.suit] );
os << CARDS[cards.card] << SUITS[cards.suit];
// set console color back to white on black
SetConsoleTextAttribute( hStdOut, 0x08 );
}
return os;
}
int main()
{
Cards cards[] = {
{ Cards::DIAMOND, Cards::ACE },
{ Cards::CLUB, Cards::JACK }
};
std::cout << cards[0] << " " << cards[1] << std::endl;
}
|