一、游戏说明:
编写的是一个模拟炸金花的纸牌游戏,游戏附有一个操作说明文档,按照文档上的操作方法,可以简单的开启游戏,整个程序包扩一个编译好的.exe文件,和两个资源文件夹,分别存有该游戏运行时候所需要的照片资源和音乐资源,用户可以直接点击exe文件运行游戏,然后按照相关操作方法来进行游戏。
二、编程语言环境介绍:
本游戏是在VC6.0环境下,用C语言加上一个easyx的C语言图形库实现的。程序源文件建立的是.cpp文件,但是程序开发是采用的C语言语法和风格,建立.cpp文件的原因是,easyx图形库的的调用的需要。
三:编写方法介绍:
本游戏,整体上是按照功能来编写的,是一种按照过程来编程而非面向对象的方法,游戏中,根据每一个游戏界面的区分,分别实现每一个游戏界面的开发,在每个界面中有相应的键盘监听,可以触发程序运行的方向,然后通过整体上的连接,将每一个界面按照功能逻辑连接成一个完整的游戏。
四: visual studio 性能分析报告:
说明: 性能测试是按照一次正常的游戏过程的执行来测试的。
图一
图二
图三
五、性能报告结果分析:
从第一张图反映整个程序的运行,整体上的资源消耗比较平稳,只是在不同的阶段有一些合理的波动,这与程序的代码的实现上是有关的,由于每一个界面的图形绘制都是通过相应的图形库函数来实现的,这种图形绘制工作量在资源的消耗上波动不是太大,因为每个界面的内容不会导致对资源的消耗有明显的区别。然后就是每个界面的监听和相关处理不同会对程序阶段性资源消耗造成一些不同。
第二张图反映热路劲的核心函数对资源的消耗,都不是单个函数的消耗,几乎全部都是有子函数的调用和运行对资源的消耗构成,因为在程序代码上看,单个函数的处理上,大量的调用了库函数和其他函数,然后整体上控制和与这些子函数进行交流通信,达到整体功能上的实现。
第三张图反映了程序运行中的几个运行次数最多,对资源消耗最大的子程序。
六、游戏缺点:
在该游戏中,由于是单机版,只能模拟炸金花的过程,由于要在一台电脑上显示两家牌,这样就与游戏中不能看到对方牌,但是又要看到自家牌的规则相违背。对这个问题的处理是,通过默认不翻牌,只在按下相关键的情况下,翻开对应牌,这就造成了游戏的用户体验上的缺陷,但这也是由于该游戏性质和单机版本这两个因素的限制。
另外就是,在该游戏中有很多位置还有待优化和补漏,游戏的虽然可以在正常的操作下正常运行,但是有些位置对非正确的操作,程序的鲁棒性还不好,因而有待于对一些特殊情况的处理上进行改进。
七、游戏运行界面展示:
图三 游戏界面1
图四 游戏界面2
八、对编写过程的总结
首先很明显的一点就是,由于C语言不适合做图形开发,因而用C语言写这个程序的时候,在图形的处理上花费了很多精力和代码量。其次,在做大一点的这种应用的开发时候,前期的规划工作一定要规划好,这样在整个开发的过程中才不会显得那么吃力,也会少很多逻辑上和其他的错误。面向过程的方法编写程序过程,虽然可以按照功能来开发,思路清晰,但是在代码复用、修改和增量改进上有欠缺,并且开发投入比较大。每一种语言都有它的优点和缺点,我们使用的时候,关键是要学会的那种开发过程中的思想和对问题的处理方法,只要运用的好,每一种语言都能做不不平凡的应用。
九、源代码:
#include<easyx.h>
#include<conio.h>
#include<time.h>
#include<windows.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<graphics.h>
#include<iostream.h>
#include<math.h>
#include<Mmsystem.h>
#pragma comment ( lib, "Winmm.lib" )
#define ok 0
#define eror 1
enum CMD
{
CMD_confirm,
// 确认
CMD_up, //上移
CMD_DOWN,
// 下移
};
char NAM1[50],NAM2[50];
int CAS1=0,CAS2=0,JETON=0,w1[3][2],w2[3][2],countgame=0;
int getCMDNum();
CMD getCmd();
int mianInterface(int x,int y,int z);
int instruction();
int shutDown();
int loading();
int welcome();
int setCash();
int gameInterface();
int initImage(int i,int j,IMAGE * p);
int Is_BaoZi(int a[3][2]);
int Is_TongHuaShun(int a[3][2]);
int Is_ShunZi(int a[3][2]);
int Is_TongHua(int a[3][2]);
int Is_DuiZi(int a[3][2]);
void Sort(int a[3][2]);
int comparePoker();
int compareOnePoker(int i,int j);
void main()
{
time_t rawtime;
struct tm * timeinfo;
FILE * fp;
char tim[50];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
srand((unsigned)time(0));
strcpy(tim,asctime (timeinfo));
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(eror);
}
else
{
fprintf(fp,"\n%s",tim);
if(fclose(fp))
{
printf("file close eror");
exit(eror);
}
}
initgraph(1024,640);
mciSendString( "open ./sound/1003.mp3 alias 1003", 0, 0, 0 );
mciSendString( "play 1003 ", 0, 0, 0 );
mianInterface(0,0,0);
/*mciSendString(L"status sound length", buf, 256, NULL);
mciSendString(L"pause sound", NULL, 0, NULL);
mciSendString(L"play sound", NULL, 0, NULL); // 从当前位置播放到文件尾
mciSendString(L"stop sound", NULL, 0, NULL);
mciSendString(L"close sound", NULL, 0, NULL);*/
}
int gameInterface()
{
int n1,n2,i=0,len,end,c2,k=0,flag[6]={0,0,0,0,0,0},view[6]={0,0,0,0,0,0},num=0,pos=2,exitprogram=0,lock=0;
int fan1[2]={-1,-1},fan2[2]={-1,-1},bigger=-1,count=0,time=15,counttime=0,flagtime=0,completeInput=0;
char game[50],cash1[50],cash2[50],ch,showtime[10],numchar[20];
IMAGE clock,pb,p1[3],p2[3];
FILE *fp;
mciSendString( "close 1000 ", 0, 0, 0 );
CAS1 -= 5, CAS2 -= 5;
JETON = 10;
loadimage(&clock,"./picture/clock.jpg", 80, 80);
loadimage(&pb,"./picture/bm.jpg", 120, 180);
n1=strlen(NAM1);
n2=strlen(NAM2);
cleardevice();
setcolor(YELLOW);
setfont( 25, 0,"楷体");
line(0,29,1024,29);
outtextxy(0,2,"天天炸金花");
setfont( 40, 0,"楷体");
outtextxy(50,50,"玩家1");
outtextxy(874,50,"玩家2");
outtextxy(50,100,NAM1);
outtextxy(974-n2*20,100,NAM2);
sprintf(cash1, "%d", CAS1);
sprintf(cash2, "%d", CAS2);
c2=strlen(cash2);
outtextxy(50,150,cash1);
outtextxy(974-c2*20,150,cash2);
sprintf(game, "%d", JETON);
len=strlen(game);
if(len%2==0)
{
outtextxy(512-(len/2)*20,550,game);
}
else
{
outtextxy(512-(len/2)*20-10,550,game);
}
putimage(472, 110, &clock, SRCINVERT);
end = comparePoker();
for(i = 0; i < 3; i++)
{
initImage(w1[i][0],w1[i][1],&p1[i]);
initImage(w2[i][0],w2[i][1],&p2[i]);
}
mciSendString( "open ./sound/chupai.mp3 alias chupai", 0, 0, 0 );
mciSendString( "play chupai ", 0, 0, 0 );
for(i=0;i<40;i+=2)
{
clearrectangle(452,300-i,572,480-i);
putimage(452, 300-i, &pb, SRCINVERT);
Sleep(100);
}
i=260;
putimage(100, i-40, &pb, SRCINVERT);
putimage(804, i-40, &pb, SRCINVERT);
Sleep(200);
clearrectangle(100,i+20,220,i+200);
clearrectangle(804,i+20,924,i+200);
putimage(100, i+20, &pb, SRCINVERT);
putimage(804, i+20, &pb, SRCINVERT);
mciSendString("close chupai", NULL, 0, NULL);
while(true)
{
BeginBatchDraw();
if(count==0)
{
k=rand()%4;
if(k==0)
mciSendString( "open ./sound/2000.mp3 alias music", 0, 0, 0 );
else if(k==1)
{
mciSendString( "open ./sound/2001.mp3 alias music", 0, 0, 0 );
}
else if(k==2)
{
mciSendString( "open ./sound/2002.mp3 alias music", 0, 0, 0 );
}
else
{
mciSendString( "open ./sound/2002.mp3 alias music", 0, 0, 0 );
}
mciSendString( "play music ", 0, 0, 0 );
}
if(count==1500)
mciSendString("close music", NULL, 0, NULL);
if(count==1501)
count=0;
begin: if(kbhit())
{
ch=getch();
switch(ch)
{
case ‘5‘:
end=2;
goto start3;
case ‘0‘:
end = 1;
goto start3;
case ‘4‘:
start1: for(k=0;k<pos;k++)
{
clearrectangle(100,i-40+k*60,220,i-40+k*60+180);
if(view[k]==1)
{
putimage(100, i-40+k*60, &p1[k], SRCINVERT);
flag[k]=1;
}
else
{
if(flag[k]==0&&ch==‘4‘)
{
putimage(100, i-40+k*60, &p1[k], SRCINVERT);
flag[k]=1;
}
else
{
putimage(100, i-40+k*60, &pb, SRCINVERT);
flag[k]=0;
}
}
}
break;
case ‘9‘:
start2: for(k=0;k<pos;k++)
{
clearrectangle(804,i-40+k*60,924,i-40+k*60+180);
if(view[k+3]==1)
{
putimage(804, i-40+k*60, &p2[k], SRCINVERT);
flag[k+3]=1;
}
else
{
if(flag[k+3]==0&&ch==‘9‘)
{
putimage(804, i-40+k*60, &p2[k], SRCINVERT);
flag[k+3]=1;
}
else
{
putimage(804, i-40+k*60, &pb, SRCINVERT);
flag[k+3]=0;
}
}
}
break;
case ‘3‘:
if(pos==2)
break;
case ‘1‘:
case ‘2‘:
k = (int)ch - 48;
k--;
if(view[k]==0)
view[k]=1;
else
view[k]=0;
flagtime =0;
goto start1;
break;
case ‘8‘:
if(pos==2)
break;
case ‘6‘:
case ‘7‘:
k = (int)ch - 48;
k -= 3;
if(view[k]==0)
view[k]=1;
else
view[k]=0;
goto start2;
break;
case ‘a‘:
case ‘A‘:
if(bigger==1||(bigger==2&&completeInput==1))
{
if(pos==2)
{
rectangle(240,280,360,330);
setfont( 20, 0,"楷体");
outtextxy(245,295,"输入筹码");
setfont( 40, 0,"楷体");
EndBatchDraw();
BeginBatchDraw();
}
else
{
rectangle(240,340,360,390);
setfont( 20, 0,"楷体");
outtextxy(245,355,"输入筹码");
setfont( 40, 0,"楷体");
EndBatchDraw();
BeginBatchDraw();
}
num = getCMDNum();
sprintf(numchar, "%d",num);
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(0);
}
else
{
if(bigger==1)
fprintf(fp,"\n%s 出筹码:%d",NAM1,num);
else
fprintf(fp,"\n%s 跟筹码:%d",NAM1,num);
if( fclose( fp ) )
{
printf( "file colse eror\n" );
exit(eror);
}
}
if(pos==2)
{
clearrectangle(240,280,360,330);
outtextxy(245,295,numchar);
}
else
{
clearrectangle(240,340,360,390);
outtextxy(245,355,numchar);
}
CAS1 -= num;
JETON += num;
clearrectangle(50,150,50+20*strlen(cash1),190);
sprintf(cash1, "%d", CAS1);
outtextxy(50,150,cash1);
sprintf(game, "%d", JETON);
len=strlen(game);
if(len%2==0)
{
outtextxy(512-(len/2)*20,550,game);
}
else
{
outtextxy(512-(len/2)*20-10,550,game);
}
if(bigger==1)
completeInput=1;
else
completeInput=0;
}
break;
case ‘l‘:
case ‘L‘:
if(bigger==2||(bigger==1&&completeInput==1))
{
if(pos==2)
{
rectangle(664,280,784,330);
setfont( 20, 0,"楷体");
outtextxy(669,295,"输入筹码");
setfont( 40, 0,"楷体");
EndBatchDraw();
BeginBatchDraw();
}
else
{
rectangle(664,340,784,390);
setfont( 20, 0,"楷体");
outtextxy(669,355,"输入筹码");
setfont( 40, 0,"楷体");
EndBatchDraw();
BeginBatchDraw();
}
num = getCMDNum();
sprintf(numchar, "%d",num);
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(eror);
}
else
{
if(bigger==2)
fprintf(fp,"\n%s 出筹码:%d",NAM2,num);
else
fprintf(fp,"\n%s 跟筹码:%d",NAM2,num);
if( fclose( fp ) )
{
printf( "file close eror\n" );
exit(eror);
}
}
if(pos==2)
{
clearrectangle(664,280,784,330);
outtextxy(705,285,numchar);
}
else
{
clearrectangle(664,340,784,390);
outtextxy(705,345,numchar);
}
CAS2 -= num;
JETON += num;
clearrectangle(974-strlen(cash2)*20,150,974,190);
sprintf(cash2, "%d", CAS2);
c2=strlen(cash2);
outtextxy(974-c2*20,150,cash2);
sprintf(game, "%d", JETON);
len=strlen(game);
if(len%2==0)
{
outtextxy(512-(len/2)*20,550,game);
}
else
{
outtextxy(512-(len/2)*20-10,550,game);
}
if(bigger==2)
completeInput=1;
else
completeInput=0;
}
break;
case 13:
if(pos==2&&lock==1)
{
pos=3;
clearrectangle(100,i+80,220,i+260);
clearrectangle(804,i+80,924,i+260); //i=260
putimage(100, i+80, &pb, SRCINVERT);
putimage(804, i+80, &pb, SRCINVERT);
flagtime=1;
goto begin;
}
else
{
if(lock==1)
{
exitprogram=1;
break;
}
}
break;
}
}
if(exitprogram==1)
break;
if(pos==2)
{
if(((view[0]+view[1])==1)&&((view[3]+view[4])==1))
{
clearrectangle(100,530,260,570);
clearrectangle(804,530,964,570);
lock=1;
if(view[0]==1)
fan1[0]=0;
if(view[1]==1)
fan1[0]=1;
if(view[3]==1)
fan2[0]=0;
if(view[4]==1)
fan2[0]=1;
bigger=compareOnePoker(fan1[0],fan2[0]);
if(bigger==1)
{
outtextxy(100,530,"请出筹码");
outtextxy(804,530,"请跟筹码");
}
else
{
if(bigger==2)
{
outtextxy(100,530,"请跟筹码");
outtextxy(804,530,"请出筹码");
}
else
{
outtextxy(100,530,"请出筹码");
outtextxy(804,530,"请出筹码");
}
}
}
else
{
outtextxy(100,530,"请翻牌 ");
outtextxy(804,530,"请翻牌 ");
}
}
else
{
if((view[0]+view[1]+view[2])==2&&(view[3]+view[4]+view[5])==2)
{
for(k=0;k<3;k++)
{
if(view[k]==1&&fan1[0]!=k)
fan1[1]=k;
if(view[k+3]==1&&fan2[0]!=k)
fan2[1]=k;
}
bigger=compareOnePoker(fan1[1],fan2[1]);
if(bigger==1)
{
outtextxy(100,530,"请出筹码");
outtextxy(804,530,"请跟筹码");
}
else
{
if(bigger==2)
{
outtextxy(100,530,"请跟筹码");
outtextxy(804,530,"请出筹码");
}
else
{
outtextxy(100,530,"请出筹码");
outtextxy(804,530,"请出筹码");
}
}
}
else
{
clearrectangle(100,530,260,570);
clearrectangle(804,530,964,570);
outtextxy(100,530,"请翻牌");
outtextxy(804,530,"请翻牌");
}
}
if(((view[0]+view[1])==1&&(view[3]+view[4])==1)||((view[0]+view[1]+view[2])==2&&(view[3]+view[4]+view[5])==2))
{
if(flagtime == 0)
{
sprintf(showtime, "%d", time);
outtextxy(472,60,showtime);
counttime++;
if(counttime%50==0)
{
clearrectangle(472,60,552,100);
time--;
if(time==-1)
{
mciSendString( "open ./sound/1005.mp3 alias 1005", 0, 0, 0 );
mciSendString( "play 1005 ", 0, 0, 0 );
counttime=0;
time=15;
}
}
}
else
{
clearrectangle(472,60,552,100);
mciSendString("close 1005", NULL, 0, NULL);
}
}
EndBatchDraw();
Sleep(20);
}
start3:
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(eror);
}
if(end==1)
{
outtextxy(160,50,"winner");
fprintf(fp,"\nwinner %s 赢得:%d,",NAM1,JETON);
CAS1+=JETON;
JETON=0;
}
else if(end==2)
{
outtextxy(744,50,"winner");
fprintf(fp,"\nwinner %s 赢得:%d,",NAM2,JETON);
CAS2+=JETON;
JETON=0;
}
else
{
outtextxy(462,50,"equal");
CAS1=CAS1+JETON/2;
CAS2=CAS2+JETON/2;
fprintf(fp,"\nwinner %s %s 平分:%d,",NAM1,NAM2,JETON);
JETON=0;
}
for(k=0;k<3;k++)
{
clearrectangle(100,i-40+k*60,220,i-40+k*60+180);
clearrectangle(804,i-40+k*60,924,i-40+k*60+180);
putimage(100, i-40+k*60, &p1[k], SRCINVERT);
putimage(804, i-40+k*60, &p2[k], SRCINVERT);
}
fprintf(fp,"\n%s 剩余本金:%d,",NAM1,CAS1);
fprintf(fp,"\n%s 剩余本金:%d,",NAM2,CAS2);
fprintf(fp,"\n");
if(fclose(fp))
{
printf("file close eror\n");
exit(eror);
}
countgame++;
EndBatchDraw();
return ok;
}
int initImage(int i,int j,IMAGE * p)
{
int temp=0,pos=10;
char path[30]={"./picture/"};
if(i>9)
{
temp = i-10;
path[pos++] = ‘1‘;
path[pos++] = temp+48;
path[pos++] = j+48;
}
else
{
path[pos++] = i+48;
path[pos++] = j+48;
}
path[pos++] = ‘.‘;
path[pos++] = ‘j‘;
path[pos++] = ‘p‘;
path[pos++] = ‘g‘;
path[pos] = ‘\0‘;
loadimage(p,path, 120, 180);
return ok;
}
int setCash()
{
int i=0,j=0,temp=0,position=0,n1=0,n2=0,cash1[20],cash2[20],c1=0,c2=0,flag=0;
char name1[50],name2[50],ch;
FILE * fp;
cleardevice();
setcolor(YELLOW);
setfont( 50, 0,"楷体");
rectangle(100,50,924,590);
line(100,110,924,110);
line(100,150,924,150);
line(512,110,512,590);
outtextxy(362,55,"请输入玩家信息");
setfont( 30, 0,"楷体");
outtextxy(180,115,"玩家1");
outtextxy(180+412,115,"玩家2");
outtextxy(115,275,"姓名");
outtextxy(115+412,275,"姓名");
rectangle(150+35,270,500,310);
rectangle(150+412+35,270,500+412,310);
outtextxy(115,275+220,"本金");
outtextxy(115+412,275+220,"本金");
rectangle(150+35,270+220,500,310+220);
rectangle(150+412+35,270+220,500+412,310+220);
while(true)
{
if(kbhit())
{
ch=getch();
switch(ch)
{
case 75:
position = 0;
break;
case 72:
if(position == 2)
position = 0;
else
{
if(position == 3)
position = 1;
}
break;
case 77:
position =1;
break;
case 80:
if(position == 0)
position = 2;
else
{
if(position == 1)
position = 3;
}
break;
case 13:
flag = 1;
break;
case 8:
if(position==0&&n1>0)
{
clearrectangle(150+35+5+n1*15-1,275,150+35+5+n1*15+16,306);
n1--;
clearrectangle(150+35+5+n1*15-1,275,150+35+5+n1*15+16,306);
}
else if(position==1&&n2>0)
{
clearrectangle(150+412+35+5+n2*15-1,275,150+412+35+5+n2*15+16,306);
n2--;
clearrectangle(150+412+35+5+n2*15-1,275,150+412+35+5+n2*15+16,306);
}
else if(position==2&&c1>0)
{
clearrectangle(150+35+5+c1*15-1,275+220,150+35+5+c1*15+16,306+220);
c1--;
clearrectangle(150+35+5+c1*15-1,275+220,150+35+5+c1*15+16,306+220);
}
else
{
if(c2>0)
{
clearrectangle(150+412+35+5+c2*15-1,275+220,1150+412+35+5+c2*15+16,306+220);
c2--;
clearrectangle(150+412+35+5+c2*15-1,275+220,1150+412+35+5+c2*15+16,306+220);
}
}
break;
default :
if((ch>=‘a‘&&ch<=‘z‘)||(ch>=‘A‘&&ch<=‘Z‘)||(ch>=‘0‘&&ch<=‘9‘)||ch==‘.‘)
{
switch (position)
{
case 0:
outtextxy(150+35+5+n1*15,275,ch);
name1[n1++] = ch;
break;
case 1:
outtextxy(150+412+35+5+n2*15,275,ch);
name2[n2++] = ch;
break;
case 2:
outtextxy(150+35+5+c1*15,275+220,ch);
cash1[c1++] = (int)ch -48;
break;
case 3:
outtextxy(150+412+35+5+c2*15,275+220,ch);
cash2[c2++] = (int)ch -48;
break;
}
}
break;
}
}
if(i<25)
{
switch(position)
{
case 0:
outtextxy(150+35+5+n1*15,275,"|");
break;
case 1:
outtextxy(150+412+35+5+n2*15,275,"|");
break;
case 2:
outtextxy(150+35+5+c1*15,275+220,"|");
break;
case 3:
outtextxy(150+412+35+5+c2*15,275+220,"|");
break;
}
}
else
{
clearrectangle(150+35+5+n1*15-1,275,150+35+5+n1*15+16,306);
clearrectangle(150+412+35+5+n2*15-1,275,150+412+35+5+n2*15+16,306);
clearrectangle(150+35+5+c1*15-1,275+220,150+35+5+c1*15+16,306+220);
clearrectangle(150+412+35+5+c2*15-1,275+220,1150+412+35+5+c2*15+16,306+220);
}
i++;
if(i==45)
i=0;
if(flag == 1)
break;
Sleep(20);
}
cash1[n1]=‘\0‘;
cash2[n2]=‘\0‘;
for(i=0;i<n1;i++)
NAM1[i] = name1[i];
NAM1[i]=‘\0‘;
for(i=0;i<n2;i++)
NAM2[i] = name2[i];
NAM2[i]=‘\0‘;
for(i=0;i<c1;i++,temp=0)
{
for(j = 1,temp = cash1[i];j<(c1-i);j++)
temp *= 10;
CAS1 += temp;
}
for(i=0,temp=0;i<c2;i++,temp=0)
{
for(j = 1,temp = cash2[i];j<(c2-i);j++)
temp *= 10;
CAS2 += temp;
}
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(eror);
}
else
{
fprintf(fp,"\n玩家1 %s 存入本金:%d",NAM1,CAS1);
fprintf(fp,"\n玩家1 %s 存入本金:%d",NAM2,CAS2);
if( fclose( fp ) )
{
printf( "The file ‘data.txt‘ was not closed\n" );
exit(eror);
}
}
return ok;
}
int loading()
{
double i=3.14;
int j=0,k=0;
cleardevice();
mciSendString("close 1003", NULL, 0, NULL);
setcolor(YELLOW);
setfont( 45, 0,"楷体");
outtextxy(400,100,"努力加载中");
while(i>=0)
{
BeginBatchDraw();
setfillcolor(YELLOW);
clearrectangle(399,379,800,430);
if(j%3==0)
{
outtextxy(400,380,"LOADING...");
}
else if(j%3==1)
{
outtextxy(400,380,"LOADING.");
}
else
outtextxy(400,380,"LOADING..");
solidpie(400,200,600,400,0,3.14);
setfillcolor(BLACK);
i = i-0.01;
solidpie(400,200,600,400,0,i);
k++;
if(k%30==0)
j++;
EndBatchDraw();
Sleep(10);
}
return ok;
}
int welcome()
{
int i=1;
cleardevice();
mciSendString( "open ./sound/1000.mp3 alias 1000", 0, 0, 0 );
mciSendString( "play 1000 ", 0, 0, 0 );
BeginBatchDraw();
while(i<=80)
{
if(i<15)
setcolor(YELLOW);
else if(i<30&&i>15)
{
setcolor(RED);
}
else if(i<45&&i>30)
{
setcolor(WHITE);
}
else if(i<60&&i>45)
{
setcolor(BLUE);
}
else
{
setcolor(GREEN);
}
setfont( i, 0,"楷体");
outtextxy(508-2*i++,290,"WELCOME!");
EndBatchDraw();
Sleep(50);
}
return ok;
}
int mianInterface(int x,int y,int z)
{
int flag=1;
char ch;
FILE * fp;
while(true)
{
cleardevice();
setcolor( YELLOW );
setfont( 50, 0,"楷体");
outtextxy(x+400,y+40,"天天炸金花");
rectangle(x+450,y+200,x+630,y+260);
setfont( 40, 0,"楷体");
outtextxy(x+460,y+210,"开始游戏");
line(x+440,y+230+z*80,x+420,y+210+z*80);
line(x+440,y+230+z*80,x+420,y+250+z*80);
line(x+420,y+210+z*80,x+420,y+250+z*80);
rectangle(x+380,y+220+z*80,x+420,y+240+z*80);
rectangle(x+450,y+200+80,x+630,y+260+80);
outtextxy(x+460,y+210+80,"游戏说明");
rectangle(x+450,y+200+80+80,x+630,y+260+80+80);
outtextxy(x+460,y+210+80+80,"退出游戏");
rectangle(x+100,y+400,x+300,y+540);
outtextxy(x+120,y+420,"↑↓选择");
outtextxy(x+120,y+480,"回车确认");
outtextxy(x+700,y+480,"天天爱游戏出品~");
switch(getCmd())
{
case CMD_up:
if(z>0)
{
z -= 1;
}
break;
case CMD_DOWN:
if(z<2)
{
z += 1;
}
break;
case CMD_confirm:
if(z==0)
{
loading();
welcome();
setCash();
while(flag)
{
mciSendString( "close 1000 ", 0, 0, 0 );
gameInterface();
flag=0;
while(true)
{
if(kbhit())
{
ch=getch();
if(ch==27)
break;
if(ch==13)
{
flag=1;
break;
}
}
Sleep(20);
}
}
if((fp=fopen("gameLog.txt","a"))==NULL)
{
printf("File open eror!\n");
exit(eror);
}
else
{
fprintf(fp,"\n共进行%d场游戏。",countgame);
if(fclose(fp))
{
printf("file close eror\n");
exit(eror);
}
}
shutDown();
}
else if(z==1)
{
instruction();
}
else
{
shutDown();
}
break;
}
Sleep(20);
}
return ok;
}
int shutDown()
{
int i=5,j=0;
char s[6]={‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘};
mciSendString( "open ./sound/1006.mp3 alias 1006", 0, 0, 0 );
mciSendString( "play 1006", 0, 0, 0 );
cleardevice();
setcolor( YELLOW );
setfont( 40, 0,"楷体");
outtextxy(200,40,"你可以按回车键查看对战记录");
outtextxy(200,90,"按ESC关闭窗口,五秒后窗口将自动关闭");
setfont( 60, 0,"楷体");
while(i>=0)
{
if(j%50==0)
outtextxy(480,300,s[i--]);
j++;
if(kbhit())
{
switch(getch())
{
case 13:
outtextxy(200,600,"list");
break;
case 27:
closegraph();
exit(ok);
}
}
Sleep(20);
}
closegraph();
exit(ok);
mciSendString( "close 1006", 0, 0, 0 );
return ok;
}
int instruction()
{
int x=100;
cleardevice();
setcolor( YELLOW );
setfont( 50, 0,"楷体");
outtextxy(350,40,"天天炸金花");
setfont( 30, 0,"楷体");
outtextxy(210,120+x,"1、本游戏适合两个玩家对战。");
outtextxy(210,160+x,"2、开始游戏前每个玩家输入自己的本金数额");
outtextxy(210,200+x,"戏过程中可根据页面提示进行相关操作.");
outtextxy(210,240+x,"3、游戏结束后,玩家可以通过查看记录日志");
outtextxy(210,280+x,"了解自己每一局游戏的状况。");
rectangle(700,560,900,610);
outtextxy(710,570,"按回车键返回");
while(true)
{
if(getCmd()==CMD_confirm)
break;
}
return ok;
}
CMD getCmd()
{
// 获取控制值
while(true)
{
// 如果有按键,返回按键对应的功能
if (kbhit())
{
switch(getch())
{
case 72:
case ‘w‘:
case ‘W‘:
return CMD_up;
case 80:
case ‘s‘:
case ‘S‘:
return CMD_DOWN;
case 13:
return CMD_confirm;
}
}
// 延时 (降低 CPU 占用率)
Sleep(20);
}
}
int getCMDNum()
{
int i = 0;
char ch;
while( true )
{
if(kbhit())
{
switch(ch=getch())
{
case ‘0‘:
i *= 10;
i += 0;
break;
case ‘1‘:
i *= 10;
i += 1;
break;
case ‘2‘:
i *= 10;
i += 2;
break;
case ‘3‘:
i *= 10;
i += 3;
break;
case ‘4‘:
i *= 10;
i += 4;
break;
case ‘5‘:
i *= 10;
i += 5;
break;
case ‘6‘:
i *= 10;
i += 6;
break;
case ‘7‘:
i *= 10;
i += 7;
break;
case ‘8‘:
i *= 10;
i += 8;
break;
case ‘9‘:
i *= 10;
i += 9;
break;
case 13:
break;
default:
return -1;
}
}
if(ch==13)
break;
Sleep(20);
}
return i;
}
int compareOnePoker(int i,int j)
{
if(w1[i][0]>w2[j][0])
return 1;
else
{
if(w1[i][0]<w2[j][0])
return 2;
else
{
if(w1[i][1]<w2[j][1])
return 1;
else
{
if(w1[i][1]>w2[j][1])
return 2;
else
return 3;
}
}
}
}
int comparePoker() //用3~15代表纸牌从3到A到2的面值,其中2最大,没有大王小王。
{
int i,j,a1[6],a2[6],flag=0,sum1=0,sum2=0; //用1~4代表黑红梅方四种花色。
for(i=0;i<6;i++)
{ //flag等于1,2,3分别对应玩家1,玩家2,手中牌大,以及相同大。
a1[i]=0;
a2[i]=0;
}
srand((unsigned)time(NULL));
for(i=0;i<3;i++)
{
w1[i][0]=rand()%13+3;
w2[i][0]=rand()%13+3;
w1[i][1]=rand()%4+1;
w2[i][1]=rand()%4+1;
sum1+=w1[i][0];
sum2+=w2[i][0];
}
Sort(w1);
Sort(w2);
a1[1]=Is_BaoZi(w1);
a2[1]=Is_BaoZi(w2);
a1[2]=Is_TongHuaShun(w1);
a2[2]=Is_TongHuaShun(w2);
a1[4]=Is_ShunZi(w1);
a2[4]=Is_ShunZi(w2);
a1[3]=Is_TongHua(w1);
a2[3]=Is_TongHua(w2);
a1[5]=Is_DuiZi(w1);
a2[5]=Is_DuiZi(w2);
for(i=1;i<6;i++)
if(a1[i]==1)
break;
for(j=1;j<6;j++)
if(a2[j]==1)
break;
if(i<j)
{
flag=1;
}
else
{
if(i>j)
{
flag=2;
}
else
{
switch(i)
{
case 1:
if(w1[0][0]>w2[0][0])
flag=1;
else
{
if(w1[0][0]<w2[0][0])
flag=2;
else
{
if(a1[4]==1&&a2[4]==0)
flag=1;
else if(a1[4]==0&&a2[4]==1)
{
flag=2;
}
else if(a1[4]==1&&a2[4]==1)
{
if(w1[0][1]<w2[0][1])
flag=1;
else if(w1[0][1]>w2[0][1])
{
flag=2;
}
else
flag=3;
}
else
{
flag=3;
}
}
}
break;
case 2:
if(w1[0][0]>w2[0][0])
flag=1;
else if(w1[0][0]<w2[0][0])
{
flag=2;
}
else
{
if(w1[0][1]<w2[0][1])
flag=1;
else if(w1[0][1]>w2[0][1])
{
flag=2;
}
else
flag=3;
}
break;
case 3:
if(w1[0][0]>w2[0][0])
flag=1;
else if(w1[0][0]<w2[0][0])
{
flag=2;
}
else
flag=3;
break;
case 4:
if(w1[0][1]<w2[0][1])
flag=1;
else if(w1[0][1]>w2[0][1])
{
flag=2;
}
else
{
if(a1[5]==1&&a2[5]==0)
flag=1;
else if(a1[5]==0&&a2[5]==1)
{
flag=2;
}
else if(a1[5]==0&&a2[5]==0)
{
if(sum1>sum2)
flag=1;
else
{
if(sum1<sum2)
flag=2;
else
flag=3;
}
}
else
{
goto A;
}
}
break;
A: case 5:
if(w1[1][0]>w2[1][0])
flag=1;
else
{
if(w1[1][0]<w2[1][0])
flag=2;
else
{
goto B;
}
}
break;
B: case 6:
if(sum1>sum2)
flag=1;
else
{
if(sum1<sum2)
flag=2;
else
flag=3;
}
break;
}
}
}
//Show(w1,w2);
if(flag==1)
return 1; //玩家1牌大
if(flag==2)
return 2; //玩家2牌大
if(flag==3)
return 3; //两个玩家牌等大
return ok;
}
int Is_BaoZi(int a[3][2])
{
if(a[0][0]==a[1][0]==a[2][0])
return 1;
else
return 0;
}
int Is_TongHuaShun(int a[3][2])
{
if((a[2][0]-a[1][0])==1&&(a[1][0]-a[0][0])==1&&a[0][1]==a[1][1]&&a[1][1]==a[2][1])
return 1;
else
return 0;
}
int Is_ShunZi(int a[3][2])
{
if((a[2][0]-a[1][0])==1&&(a[1][0]-a[0][0])==1)
return 1;
else
return 0;
}
int Is_TongHua(int a[3][2])
{
if(a[0][1]==a[1][1]&&a[1][1]==a[2][1])
return 1;
else
return 0;
}
int Is_DuiZi(int a[3][2])
{
if(a[0][0]==a[1][0]||a[0][0]==a[2][0]||a[1][0]==a[2][0])
return 1;
else
return 0;
}
void Sort(int a[3][2])
{
int i,j,temp1,temp2;
for(i=2;i>0;i--)
for(j=0;j<i;j++)
{
if(a[j][0]>a[j+1][0])
{
temp1=a[j][0];
temp2=a[j][1];
a[j][0]=a[j+1][0];
a[j][1]=a[j+1][1];
a[j+1][0]=temp1;
a[j+1][1]=temp2;
}
}
}