#include #include #include using namespace std; struct Pai { int paifu; int huase; int yanse; int dianshu; int leixing; int changdu; void Kanpai() { if (paifu == 0 || paifu == 1); else cout << "牌副参数错误!\n"; switch (huase) { case 0: cout << "黑桃"; break; case 1: cout << "红桃"; break; case 2: cout << "草花"; break; case 3: cout << "方片"; break; case -1: cout << "无色"; break; default: cout << "花色错误!\n"; break; } switch (dianshu) { case 0: cout << "A "; break; case 1: cout << "2 "; break; case 2: cout << "3 "; break; case 3: cout << "4 "; break; case 4: cout << "5 "; break; case 5: cout << "6 "; break; case 6: cout << "7 "; break; case 7: cout << "8 "; break; case 8: cout << "9 "; break; case 9: cout << "10 "; break; case 10: cout << "J "; break; case 11: cout << "Q "; break; case 12: cout << "K "; break; case -1: cout << "无点数"; break; default: cout << "点数错误!\n"; break; } switch (leixing) { case 101: cout << "【杀】" << endl; break; case 102: cout << "【闪】" << endl; break; case 103: cout << "【桃】" << endl; break; // 添加其他牌类型 default: cout << "类型参数错误!"; break; } } }; void Qishixipai(Pai A[2][4][13], Pai paidui[104]) { int i, m, x, y, z, a[104] = {0}; srand((unsigned)time(NULL)); for (i = 1; i <= 104; i++) { while (a[m = rand() % 104]); a[m] = i; } for (i = 0; i <= 103; i++) { x = (a[i] - 1) / 52; y = ((a[i] - 1) - 52 * x) / 13; z = (a[i] - 1) % 13; paidui[i] = A[x][y][z]; } } void Mopai(int* shoupaishu, Pai shoupai[20], Pai A[104], int* x, Pai B[104], int* y, int juese) { if (juese) cout << "玩家从牌堆摸2张牌\n"; else cout << "电脑从牌堆摸2张牌\n"; Pai p = A[104 - (*x)]; (*x)--; (*shoupaishu)++; shoupai[*shoupaishu - 1] = p; Pai q = A[104 - (*x)]; (*x)--; (*shoupaishu)++; shoupai[*shoupaishu - 1] = q; } int main() { Pai yuanshipaidui[2][4][13], paidui[104]; int paiduishu = 104; Qishixipai(yuanshipaidui, paidui); int shoupaishu = 0; Pai shoupai[20]; Mopai(&shoupaishu, shoupai, paidui, &paiduishu, paidui, &paiduishu, 1); return 0; }

3 条评论

  • 1