// card.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <conio.h>
using namespace std;
#define MAX_LEN 54
#define SEND_END 0
#define SEND_NOT_END 1
void Input(int* arr, int nLen);
void GetNum(int* arr, int nLen, int* a);
void PrintCard(int a);
void Output(int a, int b, int c, int d, int e);
int SendCard(int* arr, int nLen, int* a, int* b, int* c, int* d, int* e);
int main()
{
int nArr[MAX_LEN] = {0};
int nRet = 0;
int a = 0;
int b = 0;
int c = 0;
int d = 0;
int e = 0;
Input(nArr, MAX_LEN);
while (true)
{
cout << "press any key to send five cards..." << endl;
getch();
a = -1;
b = -1;
c = -1;
d = -1;
e = -1;
nRet = SendCard(nArr, MAX_LEN, &a, &b, &c, &d, &e);
Output(a, b, c, d, e);
if (SEND_END == nRet)
{
break;
}
}
return 0;
}
void Input(int* arr, int nLen)
{
int i = 0;
for (i = 0; i < nLen; i++)
{
arr[i] = 0;
}
}
int SendCard(int* arr, int nLen, int* a, int* b, int* c, int* d, int* e)
{
GetNum(arr, nLen, a);
GetNum(arr, nLen, b);
GetNum(arr, nLen, c);
GetNum(arr, nLen, d);
GetNum(arr, nLen, e);
if (-1 == *e)
{
return SEND_END;
}
else
{
return SEND_NOT_END;
}
}
void GetNum(int* arr, int nLen, int* a)
{
int i = 0;
while (true)
{
*a = rand() % 54;
if (1 == arr[*a])
{
for (i = 0;i < nLen; i++)
{
if (1 != arr[i])
{
break;
}
}
if (i < nLen)
{
continue;
}
else
{
*a = -1;
break;
}
}
else
{
arr[*a] = 1;
break;
}
}
//arr[*a] = 1;
}
void Output(int a, int b, int c, int d, int e)
{
PrintCard(a);
PrintCard(b);
PrintCard(c);
PrintCard(d);
PrintCard(e);
}
void PrintCard(int a)
{
int n = 0;
char ch = '/0';
if (-1 == a)
{
cout << "没有牌" << endl;
return;
}
if (53 == a)
{
cout << "大王" << endl;
}
else if (52 == a)
{
cout << "小王" << endl;
}
else
{
switch (a % 4)
{
case 0:
cout << "黑桃";
break;
case 1:
cout << "红桃";
break;
case 2:
cout << "梅花";
break;
case 3:
cout << "方块";
break;
default:
cout << "error";
break;
}
n = a / 4 + 1;
switch (n)
{
case 1:
ch = 'A';
break;
case 11:
ch = 'J';
break;
case 12:
ch = 'Q';
break;
case 13:
ch = 'K';
break;
default:
cout << n << endl;
return;
}
cout << ch << endl;
}
}