This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/ex5/ex5.cpp
2021-10-27 23:40:44 +08:00

145 lines
No EOL
2.9 KiB
C++

#include "vec.cpp"
#include "list.cpp"
#include <time.h>
#include <stdio.h>
std::string PU[54] = {
"1A", "1B", "1C", "1D",
"2A", "2B", "2C", "2D",
"3A", "3B", "3C", "3D",
"4A", "4B", "4C", "4D",
"5A", "5B", "5C", "5D",
"6A", "6B", "6C", "6D",
"7A", "7B", "7C", "7D",
"8A", "8B", "8C", "8D",
"9A", "9B", "9C", "9D",
"XA", "XB", "XC", "XD",
"JA", "JB", "JC", "JD",
"QA", "QB", "QC", "QD",
"KA", "KB", "KC", "KD",
"BJ", "RJ"};
int main()
{
int xipai_flag = 0;
printf("生成随机扑克序列\n");
srand(time(NULL));
Vec v(54, 2);
// v.printall();
List l;
printf("开始建立链表\n");
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
}
Begin:
printf("\n是否重新洗牌?(0/1)");
scanf("%d", &xipai_flag);
if (xipai_flag == 1)
{
v.reorder();
l.clear();
printf("开始建立链表\n");
for (int i = 0; i <= 53; i++)
{
l.firstInsert(v.get(i));
std::cout << PU[l[0]] << " ";
if (i % 2 != 0)
printf("\n");
}
xipai_flag == 0;
goto Begin;
}
printf("开始发牌\n");
List p1, p2, p3;
for (int i = 0; i <= 53; i++)
{
switch (i % 3)
{
case 0:
p1.firstInsert(l[i]);
break;
case 1:
p2.firstInsert(l[i]);
break;
case 2:
p3.firstInsert(l[i]);
break;
}
}
l.clear();
p1.sort();
p2.sort();
p3.sort();
int player = 0, opt = 0;
List *pai;
select:
printf("选择玩家(1/2/3)");
scanf("%d", &player);
switch (player)
{
case 1:
pai = &p1;
break;
case 2:
pai = &p2;
break;
case 3:
pai = &p3;
break;
default:
printf("失败\n");
goto select;
}
while (1)
{
printf("1看牌2出牌3查看牌堆4结束");
scanf("%d", &opt);
switch (opt)
{
case 1:
for (int i = 0; i < (*pai).getSize(); i++)
{
std::cout << i << ": " << PU[(*pai)[i]] << "\n";
}
printf("剩余%d张牌\n", pai->getSize());
break;
case 2:
printf("选择:");
scanf("%d", &opt);
// l.firstInsert((*pai)[opt]);
std::cout << "打出" << PU[l.firstInsert((*pai).remove(opt))];
printf("\n");
printf("剩余%d张牌\n", pai->getSize());
break;
case 3:
for (int i = 0; i < l.getSize(); i++)
{
std::cout << i << ": " << PU[l[i]];
printf("\n");
}
break;
case 4:
goto select;
default:
printf("失败\n");
}
}
return 0;
}