C语言编程,纸牌游戏
编号为1-52张牌,正面向上,从第2张开始,以2为基数,是2的倍数的牌翻一次,直到最后一张牌;然后,从第3张开始,以3为基数,是3的倍数的牌翻一次,直到最后一张牌;然后&...
编号为1-52张牌,正面向上,从第2张开始,以2为基数,是2的倍数的牌翻一次,直到最后一张牌;然后,从第3张开始,以3为基数,是3的倍数的牌翻一次,直到最后一张牌;然后„从第4张开始,以4为基数,是4的倍数的牌翻一次,直到最后一张牌;...再依次5的倍数的牌翻一次,6的,7的直到以52为基数的翻过。模拟上述过程,输出每轮正面向上的牌。(看清楚,每一轮输出,求带点注释)
展开
3个回答
展开全部
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <graphics.h>
#include <conio.h>
#define ESC 0x1b
struct card
{
char color;
int number;
int signin;
}a[52]={{3,2,1},{3,3,1},{3,4,1},{3,5,1},{3,6,1},{3,7,1},{3,8,1},{3,9,1},{3,10,1},{3,74,1},{3,81,1},{3,75,1},{3,65,1},
{4,2,1},{4,3,1},{4,4,1},{4,5,1},{4,6,1},{4,7,1},{4,8,1},{4,9,1},{4,10,1},{4,74,1},{4,81,1},{4,75,1},{4,65,1},
{5,2,1},{5,3,1},{5,4,1},{5,5,1},{5,6,1},{5,7,1},{5,8,1},{5,9,1},{5,10,1},{5,74,1},{5,81,1},{5,75,1},{5,65,1},
{6,2,1},{6,3,1},{6,4,1},{6,5,1},{6,6,1},{6,7,1},{6,8,1},{6,9,1},{6,10,1},{6,74,1},{6,81,1},{6,75,1},{6,65,1}},b[52];
char s[10];
int d[52];
fan(int n)
{
if(a[n].signin==0)
a[n].signin=1;
else a[n].signin=0;
return;
}
suiji()
{
int t=0,j,i=0,struction;
for(i=0;i<=51;i++)
d[i]=-1;
i=0;
randomize();
while(i<52)
{
struction=random(52);
for(j=0;j<i;j++)
{
if(d[j]==struction)
{
t=1;
break;
}
}
if(t==0)
{
d[i]=struction;
i++;
}
else t=0;
}
return;
}
card(int n)
{
int y,x=n%13,x1=d[n]%13,y1;
char s1[2],r[2];
y=(n-x)/13;
setcolor(15);
line(49*x,80*y+42,49*x,80*y+117);
line(49*x+47,80*y+42,49*x+47,80*y+117);
line(49*x,80*y+42,49*x+47,80*y+42);
line(49*x,80*y+117,49*x+47,80*y+117);
for(y1=1;y1<75;y1++)
{
setcolor(15);
line(49*x+1,80*y+y1+42,49*x+45,80*y+y1+42);
}
if(a[n].signin==1)
{
setcolor(1);
if(a[d[n]].color==3||a[d[n]].color==4)
setcolor(RED);
sprintf(s1,"%c",a[d[n]].color);
outtextxy(49*x+3,80*y+45,s1);
if(x1<9)
sprintf(r,"%d",a[d[n]].number);
else sprintf(r,"%c",a[d[n]].number);
outtextxy(49*x+3,80*y+54,r);
}
else against(n);
setcolor(WHITE);
return;
}
against(int n)
{
int y,y1,x=n%13;
y=(n-x)/13;
for(y1=1;y1<75;y1++)
{
setcolor(BLUE);
line(49*x+1,80*y+y1+42,49*x+45,80*y+y1+42);
}
setcolor(15);
return;
}
draw(int n,int m)
{
int i4;
setcolor(YELLOW);
sprintf(s,"Base: %d",n);
outtextxy(150,420,s);
if(d[m-1]%13<9&&d[m-1]%13>=0)
sprintf(s,"Card: %c %d",a[d[m-1]].color,a[d[m-1]].number);
else sprintf(s,"Card: %c %c",a[d[m-1]].color,a[d[m-1]].number);
outtextxy(150,430,s);
setcolor(15);
for(i4=0;i4<52;i4++)
{
card(i4);
}
return;
}
frame(int n)
{
int y,x=n%13;
y=(n-x)/13;
setcolor(RED);
line(49*x,80*y+42,49*x,80*y+117);
line(49*x+47,80*y+42,49*x+47,80*y+117);
line(49*x,80*y+42,49*x+47,80*y+42);
line(49*x,80*y+117,49*x+47,80*y+117);
setcolor(15);
return;
}
huatu(int i,int j)
{
int n,m,i1=i,b,b2,j1=j,sign=0,tar=0,i2=2,k=1,p,sign1=0;
char u='',u1='',c[7][8],chh;
setbkcolor(3);
while(1)
{
loop:
sprintf(c[0],"File");
sprintf(c[1],"Option");
sprintf(c[2],"Help");
sprintf(c[3],"New");
sprintf(c[4],"Exit");
sprintf(c[5],"Auto");
sprintf(c[6],"Manual");
while(i2<=52)
{
k=1;
while(i2*k<=52)
{
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
outtextxy(8+58*m,27,c[m]);
if(m==i1)
{
setcolor(0);
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
outtextxy(8+58*m,27,c[m]);
}
if(kbhit())
{
chh=getch();
if(chh==0x1b)
{
u='';
u1='';
goto loop;
}
}
}
if(u!='N')
{
sign1=1;
break;
}
if(u=='N')
{
if(u1!='A'&&u1!='M')
{
p=i2*k;
draw(i2,p);
sign1=1;
break;
}
if(u1=='A'||u1=='M')
{
p=i2*k;
draw(i2,p);
sign1=0;
fan(i2*k-1);
frame(i2*k-1);
if(u1=='M')
{
outtextxy(150,440,"Press any key to continue!");
getch();
}
cleardevice();
k++;
}
}
}
if(sign1==1)break;
i2++;
}
if(i2>=52)
{
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
outtextxy(150,420,"Press any key to continue!");
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
outtextxy(8+58*m,27,c[m]);
if(m==i1)
{
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
outtextxy(8+58*m,27,c[m]);
}
} /*打印一级菜单*/
getch();
cleardevice();
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
if(m==i1)
{
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
}
outtextxy(8+58*m,27,c[m]);
}
draw(52,52);
}
if(u1=='M'||u1=='A')
{
u1='';
u='';
}
b=getch();
while(1)
{
if(b==100)
{
i1=(i1+1)%3;
break;
}
if(b==97)
{
if(i1==0)
{
i1=2;
break;
}
else
{
i1=i1-1;
break;
}
}
/* if(b==0x1b)
{
closegraph();
exit(1);
} */
if(b==13)
{
while(1)
{
if(i1!=2)
{
if(sign!=1)
{
setcolor(YELLOW);
for(m=1;m<=2;m++)
{
line(58*i1+3,38+15*(m-1),58*i1+3,53+15*(m-1));
line(58*i1+3,53+15*(m-1),58*i1+58,53+15*(m-1));
line(58*i1+58,38+15*(m-1),58*i1+58,53+15*(m-1));
line(58*i1+3,38+15*(m-1),58*i1+58,38+15*(m-1));
setcolor(3);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(m-1)+n,58*i1+57,39+15*(m-1)+n);
}
if(m==j1+1)
{
setcolor(3);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(tar)+n,58*i1+57,39+15*(tar)+n);
}
setcolor(BLUE);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(j1)+n,58*i1+57,39+15*(j1)+n);
}
tar=j1;
}
setcolor(YELLOW);
}
setcolor(YELLOW);
if(i1==0)
{
outtextxy(8+58*i1,43,c[i1+3]);
outtextxy(8+58*i1,58,c[i1+4]);
}
else
{
outtextxy(8+58*i1,43,c[i1+4]);
outtextxy(8+58*i1,58,c[i1+5]);
}
}
if(sign==1)break;
setcolor(YELLOW);
while(1)
{
b2=getch();
if(b2==115)
{
j1=(j1+1)%2;
break;
}
if(b2==119)
{
if(j1==1)
{
j1=0; break;
}
if(j1==0)
{
j1=1; break;
}
}
if(b2==0x1b)
{
sign=1;
j1=0;
break;
}
if(b2==13)
{
if(i1==0&&j1==1)
{
closegraph();
exit(1);
}
if(i1==0&&j1==0)
{
u='N';
suiji();
for(n=0;n<52;n++)
{
a[n].signin=1;
}
n=0;
}
if(i1==1&&j1==0)
{
u1='A';
if(u!='N') u1='';
}
if(i1==1&&j1==1)
{
u1='M';
if(u!='N') u1='';
}
sign=1;
j1=0;
break;
}
else continue;
}
}
else
{
sign=1;
outtextxy(100,100,"Copyright");
circle(180,104,5);
outtextxy(177,101,"C");
getch();
break;
}
}
}
else break;
if(sign==1)
{
sign=0;
break;
}
}
cleardevice();
i2=2;
k=1;
}
}
main()
{
int k,gm=2,gd=9;
initgraph(&gd,&gm,"");
huatu(0,0);
getch();
}
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <graphics.h>
#include <conio.h>
#define ESC 0x1b
struct card
{
char color;
int number;
int signin;
}a[52]={{3,2,1},{3,3,1},{3,4,1},{3,5,1},{3,6,1},{3,7,1},{3,8,1},{3,9,1},{3,10,1},{3,74,1},{3,81,1},{3,75,1},{3,65,1},
{4,2,1},{4,3,1},{4,4,1},{4,5,1},{4,6,1},{4,7,1},{4,8,1},{4,9,1},{4,10,1},{4,74,1},{4,81,1},{4,75,1},{4,65,1},
{5,2,1},{5,3,1},{5,4,1},{5,5,1},{5,6,1},{5,7,1},{5,8,1},{5,9,1},{5,10,1},{5,74,1},{5,81,1},{5,75,1},{5,65,1},
{6,2,1},{6,3,1},{6,4,1},{6,5,1},{6,6,1},{6,7,1},{6,8,1},{6,9,1},{6,10,1},{6,74,1},{6,81,1},{6,75,1},{6,65,1}},b[52];
char s[10];
int d[52];
fan(int n)
{
if(a[n].signin==0)
a[n].signin=1;
else a[n].signin=0;
return;
}
suiji()
{
int t=0,j,i=0,struction;
for(i=0;i<=51;i++)
d[i]=-1;
i=0;
randomize();
while(i<52)
{
struction=random(52);
for(j=0;j<i;j++)
{
if(d[j]==struction)
{
t=1;
break;
}
}
if(t==0)
{
d[i]=struction;
i++;
}
else t=0;
}
return;
}
card(int n)
{
int y,x=n%13,x1=d[n]%13,y1;
char s1[2],r[2];
y=(n-x)/13;
setcolor(15);
line(49*x,80*y+42,49*x,80*y+117);
line(49*x+47,80*y+42,49*x+47,80*y+117);
line(49*x,80*y+42,49*x+47,80*y+42);
line(49*x,80*y+117,49*x+47,80*y+117);
for(y1=1;y1<75;y1++)
{
setcolor(15);
line(49*x+1,80*y+y1+42,49*x+45,80*y+y1+42);
}
if(a[n].signin==1)
{
setcolor(1);
if(a[d[n]].color==3||a[d[n]].color==4)
setcolor(RED);
sprintf(s1,"%c",a[d[n]].color);
outtextxy(49*x+3,80*y+45,s1);
if(x1<9)
sprintf(r,"%d",a[d[n]].number);
else sprintf(r,"%c",a[d[n]].number);
outtextxy(49*x+3,80*y+54,r);
}
else against(n);
setcolor(WHITE);
return;
}
against(int n)
{
int y,y1,x=n%13;
y=(n-x)/13;
for(y1=1;y1<75;y1++)
{
setcolor(BLUE);
line(49*x+1,80*y+y1+42,49*x+45,80*y+y1+42);
}
setcolor(15);
return;
}
draw(int n,int m)
{
int i4;
setcolor(YELLOW);
sprintf(s,"Base: %d",n);
outtextxy(150,420,s);
if(d[m-1]%13<9&&d[m-1]%13>=0)
sprintf(s,"Card: %c %d",a[d[m-1]].color,a[d[m-1]].number);
else sprintf(s,"Card: %c %c",a[d[m-1]].color,a[d[m-1]].number);
outtextxy(150,430,s);
setcolor(15);
for(i4=0;i4<52;i4++)
{
card(i4);
}
return;
}
frame(int n)
{
int y,x=n%13;
y=(n-x)/13;
setcolor(RED);
line(49*x,80*y+42,49*x,80*y+117);
line(49*x+47,80*y+42,49*x+47,80*y+117);
line(49*x,80*y+42,49*x+47,80*y+42);
line(49*x,80*y+117,49*x+47,80*y+117);
setcolor(15);
return;
}
huatu(int i,int j)
{
int n,m,i1=i,b,b2,j1=j,sign=0,tar=0,i2=2,k=1,p,sign1=0;
char u='',u1='',c[7][8],chh;
setbkcolor(3);
while(1)
{
loop:
sprintf(c[0],"File");
sprintf(c[1],"Option");
sprintf(c[2],"Help");
sprintf(c[3],"New");
sprintf(c[4],"Exit");
sprintf(c[5],"Auto");
sprintf(c[6],"Manual");
while(i2<=52)
{
k=1;
while(i2*k<=52)
{
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
outtextxy(8+58*m,27,c[m]);
if(m==i1)
{
setcolor(0);
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
outtextxy(8+58*m,27,c[m]);
}
if(kbhit())
{
chh=getch();
if(chh==0x1b)
{
u='';
u1='';
goto loop;
}
}
}
if(u!='N')
{
sign1=1;
break;
}
if(u=='N')
{
if(u1!='A'&&u1!='M')
{
p=i2*k;
draw(i2,p);
sign1=1;
break;
}
if(u1=='A'||u1=='M')
{
p=i2*k;
draw(i2,p);
sign1=0;
fan(i2*k-1);
frame(i2*k-1);
if(u1=='M')
{
outtextxy(150,440,"Press any key to continue!");
getch();
}
cleardevice();
k++;
}
}
}
if(sign1==1)break;
i2++;
}
if(i2>=52)
{
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
outtextxy(150,420,"Press any key to continue!");
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
outtextxy(8+58*m,27,c[m]);
if(m==i1)
{
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
outtextxy(8+58*m,27,c[m]);
}
} /*打印一级菜单*/
getch();
cleardevice();
setcolor(9);
for(n=0;n<=18;n++)
line(0,n,639,n);
setcolor(15);
outtextxy(290,10,"Card Game");
setcolor(YELLOW);
for(n=19;n<=40;n++)
line(0,n,639,n);
for(m=0;m<=2;m++)
{
setcolor(0);
line(58*m+3,22,58*m+3,38);
line(58*m+3,38,58*m+58,38);
line(58*m+58,22,58*m+58,38);
line(58*m+3,22,58*m+58,22);
if(m==i1)
{
for(n=0;n<=16;n++)
line(58*m+3,22+n,58*m+58,22+n);
setcolor(YELLOW);
}
outtextxy(8+58*m,27,c[m]);
}
draw(52,52);
}
if(u1=='M'||u1=='A')
{
u1='';
u='';
}
b=getch();
while(1)
{
if(b==100)
{
i1=(i1+1)%3;
break;
}
if(b==97)
{
if(i1==0)
{
i1=2;
break;
}
else
{
i1=i1-1;
break;
}
}
/* if(b==0x1b)
{
closegraph();
exit(1);
} */
if(b==13)
{
while(1)
{
if(i1!=2)
{
if(sign!=1)
{
setcolor(YELLOW);
for(m=1;m<=2;m++)
{
line(58*i1+3,38+15*(m-1),58*i1+3,53+15*(m-1));
line(58*i1+3,53+15*(m-1),58*i1+58,53+15*(m-1));
line(58*i1+58,38+15*(m-1),58*i1+58,53+15*(m-1));
line(58*i1+3,38+15*(m-1),58*i1+58,38+15*(m-1));
setcolor(3);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(m-1)+n,58*i1+57,39+15*(m-1)+n);
}
if(m==j1+1)
{
setcolor(3);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(tar)+n,58*i1+57,39+15*(tar)+n);
}
setcolor(BLUE);
for(n=0;n<=13;n++)
{
line(58*i1+4,39+15*(j1)+n,58*i1+57,39+15*(j1)+n);
}
tar=j1;
}
setcolor(YELLOW);
}
setcolor(YELLOW);
if(i1==0)
{
outtextxy(8+58*i1,43,c[i1+3]);
outtextxy(8+58*i1,58,c[i1+4]);
}
else
{
outtextxy(8+58*i1,43,c[i1+4]);
outtextxy(8+58*i1,58,c[i1+5]);
}
}
if(sign==1)break;
setcolor(YELLOW);
while(1)
{
b2=getch();
if(b2==115)
{
j1=(j1+1)%2;
break;
}
if(b2==119)
{
if(j1==1)
{
j1=0; break;
}
if(j1==0)
{
j1=1; break;
}
}
if(b2==0x1b)
{
sign=1;
j1=0;
break;
}
if(b2==13)
{
if(i1==0&&j1==1)
{
closegraph();
exit(1);
}
if(i1==0&&j1==0)
{
u='N';
suiji();
for(n=0;n<52;n++)
{
a[n].signin=1;
}
n=0;
}
if(i1==1&&j1==0)
{
u1='A';
if(u!='N') u1='';
}
if(i1==1&&j1==1)
{
u1='M';
if(u!='N') u1='';
}
sign=1;
j1=0;
break;
}
else continue;
}
}
else
{
sign=1;
outtextxy(100,100,"Copyright");
circle(180,104,5);
outtextxy(177,101,"C");
getch();
break;
}
}
}
else break;
if(sign==1)
{
sign=0;
break;
}
}
cleardevice();
i2=2;
k=1;
}
}
main()
{
int k,gm=2,gd=9;
initgraph(&gd,&gm,"");
huatu(0,0);
getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
需要花色么?
更多追问追答
追问
就是1-52数字,第一轮翻,然后输出,第二轮,再输出,以此类推
追答
每张牌上数字分别是1-52,不是扑克牌?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |