一、游戲說明:
編寫的是一個模擬炸金花的紙牌游戲,游戲附有一個操作說明文檔,按照文檔上的操作方法,可以簡單的開啟游戲,整個程序包擴一個編譯好的.exe文件,和兩個資源文件夾,分別存有該游戲運行時候所需要的照片資源和音樂資源,用戶可以直接點擊exe文件運行游戲,然後按照相關操作方法來進行游戲。
二、編程語言環境介紹:
本游戲是在VC6.0環境下,用C語言加上一個easyx的C語言圖形庫實現的。程序源文件建立的是.cpp文件,但是程序開發是采用的C語言語法和風格,建立.cpp文件的原因是,easyx圖形庫的的調用的需要。
三:編寫方法介紹:
本游戲,整體上是按照功能來編寫的,是一種按照過程來編程而非面向對象的方法,游戲中,根據每一個游戲界面的區分,分別實現每一個游戲界面的開發,在每個界面中有相應的鍵盤監聽,可以觸發程序運行的方向,然後通過整體上的連接,將每一個界面按照功能邏輯連接成一個完整的游戲。
四: visual studio 性能分析報告:
說明: 性能測試是按照一次正常的游戲過程的執行來測試的。
圖一
圖二
圖三
五、性能報告結果分析:
從第一張圖反映整個程序的運行,整體上的資源消耗比較平穩,只是在不同的階段有一些合理的波動,這與程序的代碼的實現上是有關的,由於每一個界面的圖形繪制都是通過相應的圖形庫函數來實現的,這種圖形繪制工作量在資源的消耗上波動不是太大,因為每個界面的內容不會導致對資源的消耗有明顯的區別。然後就是每個界面的監聽和相關處理不同會對程序階段性資源消耗造成一些不同。
第二張圖反映熱路勁的核心函數對資源的消耗,都不是單個函數的消耗,幾乎全部都是有子函數的調用和運行對資源的消耗構成,因為在程序代碼上看,單個函數的處理上,大量的調用了庫函數和其他函數,然後整體上控制和與這些子函數進行交流通信,達到整體功能上的實現。
第三張圖反映了程序運行中的幾個運行次數最多,對資源消耗最大的子程序。
六、游戲缺點:
在該游戲中,由於是單機版,只能模擬炸金花的過程,由於要在一台電腦上顯示兩家牌,這樣就與游戲中不能看到對方牌,但是又要看到自家牌的規則相違背。對這個問題的處理是,通過默認不翻牌,只在按下相關鍵的情況下,翻開對應牌,這就造成了游戲的用戶體驗上的缺陷,但這也是由於該游戲性質和單機版本這兩個因素的限制。
另外就是,在該游戲中有很多位置還有待優化和補漏,游戲的雖然可以在正常的操作下正常運行,但是有些位置對非正確的操作,程序的魯棒性還不好,因而有待於對一些特殊情況的處理上進行改進。
七、游戲運行界面展示:
圖三 游戲界面1
圖四 游戲界面2
八、對編寫過程的總結
首先很明顯的一點就是,由於C語言不適合做圖形開發,因而用C語言寫這個程序的時候,在圖形的處理上花費了很多精力和代碼量。其次,在做大一點的這種應用的開發時候,前期的規劃工作一定要規劃好,這樣在整個開發的過程中才不會顯得那麼吃力,也會少很多邏輯上和其他的錯誤。面向過程的方法編寫程序過程,雖然可以按照功能來開發,思路清晰,但是在代碼復用、修改和增量改進上有欠缺,並且開發投入比較大。每一種語言都有它的優點和缺點,我們使用的時候,關鍵是要學會的那種開發過程中的思想和對問題的處理方法,只要運用的好,每一種語言都能做不不平凡的應用。
九、源代碼:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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
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
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
NAM1[i]='\0';
for(i=0;i
NAM2[i]='\0';
for(i=0;i
for(j = 1,temp = cash1[i];j<(c1-i);j++)
temp *= 10;
CAS1 += temp;
}
for(i=0,temp=0;i
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]
else
{
if(w1[i][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
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]
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]
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]
flag=2;
}
else
{
if(w1[0][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]
flag=2;
}
else
flag=3;
break;
case 4:
if(w1[0][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
else
flag=3;
}
}
else
{
goto A;
}
}
break;
A: case 5:
if(w1[1][0]>w2[1][0])
flag=1;
else
{
if(w1[1][0]
else
{
goto B;
}
}
break;
B: case 6:
if(sum1>sum2)
flag=1;
else
{
if(sum1
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 {
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;
}
}
}