用C语言编程扑克牌搓点游戏,急!
用C语言编写扑克牌搓点游戏,规则:您将随机抽取其中两张和电脑进行对抗,2张牌相加,个位大的胜出,其中对子比单牌大,若都是对子,对子大的胜出。您可以根据提示下注,起始资金均...
用C语言编写扑克牌搓点游戏,规则:您将随机抽取其中两张和电脑进行对抗,2张牌相加,个位大的胜出,其中对子比单牌大,若都是对子,对子大的胜出。您可以根据提示下注,起始资金均为1000元,当一方财产小于0时,宣布破产,另一方胜出。急!急!急!拜托……
要求打印扑克牌的图标,还有用A J Q K,来表示 展开
要求打印扑克牌的图标,还有用A J Q K,来表示 展开
4个回答
展开全部
给你修改好了。20分,有点少了,呵呵。
/*游戏:扑克牌搓点游戏
规则:您将随机抽取其中两张和电脑进行对抗,
2张牌相加,个位大的胜出,其中对子比单牌大,
若都是对子,对子大的胜出。
您可以根据提示下注,起始资金均为1000元,
当一方财产小于0时,宣布破产,另一方胜出。
作者:于吉祥
日期:20090220
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_M 1000
enum colour
{
HEI = 0,
HONG,
MEI,
FANG,
};
void display(int number , int sign)
{
printf("%s\n","╭——╮");
switch(number)
{
case 0:
printf("%s\n","│0 │");
break;
case 1:
printf("%s\n","│A │");
break;
case 2:
printf("%s\n","│2 │");
break;
case 3:
printf("%s\n","│3 │");
break;
case 4:
printf("%s\n","│4 │");
break;
case 5:
printf("%s\n","│5 │");
break;
case 6:
printf("%s\n","│6 │");
break;
case 7:
printf("%s\n","│7 │");
break;
case 8:
printf("%s\n","│8 │");
break;
case 9:
printf("%s\n","│9 │");
break;
case 10:
printf("%s\n","│10 │");
break;
case 11:
printf("%s\n","│J │");
break;
case 12:
printf("%s\n","│Q │");
break;
case 13:
printf("%s\n","│K │");
break;
default:
printf("error");
break;
}
// printf("%s\n","│ │");
printf("%s","│ ");
switch(sign)
{
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\n"," │");
printf("%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];
printf("扑克牌搓点游戏\n");
printf("---------------\n");
system("pause");
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]);
printf("牌已经抽取,你抽到的牌为:\n");
for(i=0;i<2;i++)
display(Per[i],Colour_Per[i]);
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;
}
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;
}
// printf("电脑抽到的牌为:%d %d\n",Com[0],Com[1]);
printf("电脑抽到的牌为:\n");
for(i=0;i<2;i++)
display(Com[i],Colour_Com[i]);
system("pause");
}
printf("游戏结束!");
system("pause");
}
/*游戏:扑克牌搓点游戏
规则:您将随机抽取其中两张和电脑进行对抗,
2张牌相加,个位大的胜出,其中对子比单牌大,
若都是对子,对子大的胜出。
您可以根据提示下注,起始资金均为1000元,
当一方财产小于0时,宣布破产,另一方胜出。
作者:于吉祥
日期:20090220
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define MAX_M 1000
enum colour
{
HEI = 0,
HONG,
MEI,
FANG,
};
void display(int number , int sign)
{
printf("%s\n","╭——╮");
switch(number)
{
case 0:
printf("%s\n","│0 │");
break;
case 1:
printf("%s\n","│A │");
break;
case 2:
printf("%s\n","│2 │");
break;
case 3:
printf("%s\n","│3 │");
break;
case 4:
printf("%s\n","│4 │");
break;
case 5:
printf("%s\n","│5 │");
break;
case 6:
printf("%s\n","│6 │");
break;
case 7:
printf("%s\n","│7 │");
break;
case 8:
printf("%s\n","│8 │");
break;
case 9:
printf("%s\n","│9 │");
break;
case 10:
printf("%s\n","│10 │");
break;
case 11:
printf("%s\n","│J │");
break;
case 12:
printf("%s\n","│Q │");
break;
case 13:
printf("%s\n","│K │");
break;
default:
printf("error");
break;
}
// printf("%s\n","│ │");
printf("%s","│ ");
switch(sign)
{
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\n"," │");
printf("%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];
printf("扑克牌搓点游戏\n");
printf("---------------\n");
system("pause");
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]);
printf("牌已经抽取,你抽到的牌为:\n");
for(i=0;i<2;i++)
display(Per[i],Colour_Per[i]);
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;
}
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;
}
// printf("电脑抽到的牌为:%d %d\n",Com[0],Com[1]);
printf("电脑抽到的牌为:\n");
for(i=0;i<2;i++)
display(Com[i],Colour_Com[i]);
system("pause");
}
printf("游戏结束!");
system("pause");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询