#include#include #include int N; //牌序int integral_player; //玩家积分int integral_computer; //电脑积分int card[52]= {102,103,104,105,106,107,108,109,110,111,112,113,114,202,203,204,205,206,207,208,209,210,211,212,213,214 ,302,303,304,305,306,307,308,309,310,311,312,313,314,402,403,404,405,406,407,408,409,410,411,412,413,414, };int player1[10]= {0,};int player2[10]= {0,};int player1_card=0;int player2_card=0;void show_cards(int i); //示牌void riffle(); //洗牌void Send_cards(); //发牌void add_player(); //玩家要牌void add_computer(); //电脑要牌void cal_point(); //计算点数void integral_read(); //积分读取,显示void integral_write(); //积分写入int main(){ char choose; integral_read(); //积分读取 do { //printf("洗牌測试 \n"); riffle(); //洗牌 Send_cards(); //发牌 add_player(); //玩家要牌 add_computer(); //电脑要牌 cal_point(); //计算点数 integral_write(); //积分写入 printf("******************* SUCCESS ***********************\n"); printf("按 N 退出,其它键继续....\n\n"); fflush(stdin); choose=getchar(); printf("\n"); } while (choose !='n'&&choose!='N'); return 0;}void riffle(){ int a,t,i; srand(time(0)); /*for (i=0; i<52; i++) { if (i%13==0) { printf("\n\n"); } show_cards(i); } printf("\n\n"); printf("上面是正常牌序,后面是洗牌后的牌序\n"); //洗牌測试*/ for (i=0; i<52; i++) { a=rand()%52; t=card[i]; card[i]=card[a]; card[a]=t; } N=0; //牌序重置; player1_card=0; //玩家牌序重置。 player2_card=0; //电脑牌序重置; /*for (i=0; i<52; i++) //洗牌測试 { if (i%13==0) { printf("\n\n"); } show_cards(i); } printf("\n\n");*/}void Send_cards(){ int j; printf("玩家拿牌:"); for (j=0; j<2; j++) { show_cards(N); player1[player1_card]=card[N]; player1_card++; N++; } printf("\n\n"); printf("电脑拿牌:"); for (j=0; j<2; j++) { show_cards(N); player2[player2_card]=card[N]; player2_card++; N++; } printf("\n\n");}void show_cards(int i){ int choose; choose=card[i]/100; switch (choose) { case 1: if (card[i]%100==14) { printf("SA\t"); break; } else if (card[i]%100==13) { printf("SK\t"); break; } else if (card[i]%100==12) { printf("SQ\t"); break; } else if (card[i]%100==11) { printf("SJ\t"); break; } else { printf("S%d\t",card[i]%100); break; } case 2: if (card[i]%100==14) { printf("DA\t"); break; } else if (card[i]%100==13) { printf("DK\t"); break; } else if (card[N]%100==12) { printf("DQ\t"); break; } else if (card[i]%100==11) { printf("DJ\t"); break; } else { printf("D%d\t",card[i]%100); break; } case 3: if (card[i]%100==14) { printf("CA\t"); break; } else if (card[i]%100==13) { printf("CK\t"); break; } else if (card[i]%100==12) { printf("CQ\t"); break; } else if (card[i]%100==11) { printf("CJ\t"); break; } else { printf("C%d\t",card[i]%100); break; } case 4: if (card[N]%100==14) { printf("HA\t"); break; } else if (card[N]%100==13) { printf("HK\t"); break; } else if (card[N]%100==12) { printf("HQ\t"); break; } else if (card[i]%100==11) { printf("HJ\t"); break; } else { printf("H%d\t",card[i]%100); break; } }}void add_player(){ int choose; do { printf("玩家: 1.要牌 2.不要\040"); scanf("%d",&choose); switch (choose) { case 1: show_cards(N); player1[player1_card]=card[N]; player1_card++; N++; printf("\n"); continue; case 2: printf("不要\n"); return; } } while (1);}void add_computer(){ int i; while (1) { int choose=2; int point=0; for (i=0; i 21) { printf("玩家爆掉\n\n"); winner1=0; } else winner1=1; if (point2>21) { printf("电脑爆掉\n\n"); winner2=0; } else winner2=1; if (winner1>winner2){ printf("玩家胜,得1分\n\n"); integral_player++; return; } else if((winner1=winner2==1)){ if (point1>point2){ printf("玩家胜。得1分\n\n"); integral_player++; return; } else{ printf("电脑胜,得1分\n\n"); integral_computer++; return; } } else if ((winner1=winner2==0)){ printf("电脑胜,得1分\n\n"); integral_computer++; return; } else if (winner1
还有不完好的地方
比方 A仅仅能作为11使用 不能看情况做1 计算
假设2个牌同样 不算豹子
下次继续改进