/*扑克牌搓点游戏*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_M 1000 //设定初始资金
enum colour
{
HEI = 0,
HONG,
MEI,
FANG,
};
/*************************************** 规则 **********************************************/
void explain()
{
printf("幸运大比拼游戏\n");
printf("----------------------------------------------------------------------------\n",06,03,05,02);
printf("规则:\n\n您将随机抽取其中两张和电脑进行对抗\n\n两张牌相加,个位大的胜出,其中对子比单牌大\n\n若都是对子,对子大的胜出\n\n");
printf("您可以根据提示下注,起始资金均为1000元\n\n当一方财产小于0时,宣布破产,另一方胜出。");
system("pause");
}
/********************************* 纸牌图形输出函数 ***********************************/
void display(int number[2] , int sign[2])
{
int i;
printf("%s\n","╔══╗ ╔══╗");
for(i=0;i<2;i++)
{
switch(number[i])
{
case 0:printf("%s","║0 ║ ");break;
case 1:printf("%s","║A ║ ");break;
case 2:printf("%s","║2 ║ ");break;
case 3:printf("%s","║3 ║ ");break;
case 4:printf("%s","║4 ║ ");break;
case 5:printf("%s","║5 ║ ");break;
case 6:printf("%s","║6 ║ ");break;
case 7:printf("%s","║7 ║ ");break;
case 8:printf("%s","║8 ║ ");break;
case 9:printf("%s","║9 ║ ");break;
case 10:printf("%s","║10 ║ ");break;
case 11:printf("%s","║J ║ ");break;
case 12:printf("%s","║Q ║ ");break;
case 13:printf("%s","║K ║ ");break;
default:printf("error");
break;
}
}
printf("\n%s\n","║ ║ ║ ║");
for(i=0;i<2;i++)
{
printf("%s","║ ");
switch(sign[i])
{
case HEI:
printf("%c",06);
break;
case HONG:
printf("%c",03);
break;
case MEI:
printf("%c",05);
break;
case FANG:
printf("%c",04);
break;
default:break;
}
printf("%s"," ║ ");
}
printf("\n%s\n","║ ║ ║ ║");
printf("%s\n","╚══╝ ╚══╝");
}
/*********************************** 单局胜负判断 ****************************************/
int compare(int x[] , int y[]) //
{
int sign,a,b;
if((x[0] == x[1])&&(y[0] == y[1])) //如果两方都是对子比较谁的对子大
{
if(x[0] == y[0])sign = 0;
else if(x[0] > y[0]) sign = 1;
else sign = -1;
}
else if(x[0] == x[1]) sign = 1; //只有一方有对子时
else if(y[0] == y[1]) sign = -1;
else //双方都没对子,比较点数和的个位
{
a = (x[0]+x[1])%10; b = (y[0]+y[1])%10;
if(a == b) sign = 0;
else if(a > b) sign = 1;
else sign = -1;
}
return sign;
}
/************************************ 主函数 ***************************************/
void main()
{
int i,chip;
int Per[2],Com[2];
int Mon_Per = MAX_M , Mon_Com = MAX_M;
int Colour_Per[2] , Colour_Com[2];
explain(); //调用函数,输出游戏规则说明
while(1)
{
system("cls");
if(Mon_Per <=0) { printf("您已身无分文,游戏退出!"); break; }
if(Mon_Com <=0) { printf("电脑已经被你赢光了,恭喜你获胜!"); break; }
srand( time(NULL) );
for(i=0;i<2;i++)
{
Per[i] = rand()%13+1; Colour_Per[i] = rand()%4; Com[i] = rand()%13+1; Colour_Com[i] = rand()%4;
}
printf("当前余额:你(%d),电脑(%d)\n",Mon_Per,Mon_Com);
printf("牌已经抽取,你抽到的牌点数为:%d %d\n",Per[0],Per[1]);
display(Per,Colour_Per);
printf("请下注:");
RET: scanf("%d",&chip);
if(chip>500) { printf("最大可下注为500,请重新下注!\n"); goto RET; }
Mon_Per -= chip;
Mon_Com -= chip;
if(Mon_Per < 0) { printf("您的余额不足,请重新下注!"); Mon_Per += chip; Mon_Com += chip; goto RET; }
if(Mon_Com < 0) { printf("电脑余额不足,请重新下注!"); Mon_Per += chip; Mon_Com += chip; goto RET; }
printf("电脑抽到的牌点数为:%d %d\n",Com[0],Com[1]);
display(Com,Colour_Com);
switch(compare(Per,Com))
{
case 0: printf("平局!"); Mon_Per += chip; Mon_Com += chip; break;
case 1: printf("你赢了!"); Mon_Per += 2*chip; break;
case -1: printf("电脑赢了!"); Mon_Com += 2*chip; break;
default: printf("系统出错!"); break;
}
system("pause");
}
printf("游戏结束!");
system("pause");
}
评论0