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
|
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <cstring>
#include <ctime>
using namespace std;
void deal(int wDeck[][13], const char *wFace[], const char *wSuit[]);
// in the main before call to deal
const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
"Ten", "Jack", "Queen", "King"};
// ... end main
int main (int argc,char ** argv)
{
time_t t= time(NULL);
int wDeck[4][13];
srand(t);
for (int i = 0; i < 4; i++){
for (int j=0; j < 13; j++){
wDeck[i][j] = rand();
}
}
deal(wDeck, face, suit);
return 0;
}
void deal(int wDeck[][13], const char *wFace[], const char *wSuit[])
{
char hand[2][5][15] = {{""}};
for(int handNumber = 0; handNumber < 2; handNumber++)
{
for(int cardNumber = 1; cardNumber <= 5; cardNumber++)
{
int row = rand() % 4;
int column = rand() % 13;
while(wDeck[row][column] == 0)
{
row = rand() % 4;
column = rand() % 13;
}
wDeck[row][column] = 0;
char description[14] = "";
strcat(description, wFace[column]);
strcat(description, " ");
strcat(description, wSuit[row]);
strcpy(hand[handNumber][cardNumber - 1], description);
cout << hand[handNumber][cardNumber - 1] << endl;
}
cout << "=======================\n";
}
}
|