该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
C语言——经典小游戏——打砖块
玩法:按A与D控制球拍的移动,按S暂停游戏
百度网盘下载:http://pan.baidu.com/s/1o64ECTc
代码爆破~\(≧▽≦)/~:
#include
#include
#include
#include
#include
#include
#pragma comment (lib,"winmm.lib")
#define M 20
#define N M/2
MCIDEVICEID dev[1];
MCI_OPEN_PARMS mciOpen;
MCI_PLAY_PARMS mciPlay;
void main()
{
int a[M][N]={0},i,j,sum=0,score=0,x=N/2,y=M-1,fx=0,fy=0,p=N/2,d=N/4;
char c='1';
PlaySound("bgm.wav", NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
srand(time(0));
while(c=='1')
{
x=N/2;y=M-1;fx=0;fy=0;p=N/2;c='1';
for(i=0;i
{
for(j=0;j
{
a[i][j]=0;
a[i][j]=rand()%2;
sum+=a[i][j];
}
}
while(score
{
Sleep(100);
system("cls");
printf("打砖块游戏\n得分:%d/%d:\n",score,sum);
printf("┏");
for(j=0;j
{
printf("━");
}
printf("┓\n");
for(i=0;i
{
printf("┃");
for(j=0;j
{
if(i==y && j==x)
{
printf("●");
}
else
{
switch(a[i][j])
{
case 0:printf(" ");break;
case 1:printf("※");break;
}
}
}
printf("┃\n");
}
printf("┗");
for(j=0;j
{
if(j>p-d && j
{
printf("█");
}
else printf("━");
}
printf("┛\n");
if(kbhit())
{
c=getch();
switch(c)
{
case 'a':p--;if(y>M-2)x--;break;
case 's':system("pause");break;
case 'd':p++;if(y>M-2)x++;break;
}
}
if(y+1-2*fy=0 && x+1-2*fx=0 )
{
if(a[y+1-2*fy][x+1-2*fx]==0)
{
x=x+1-2*fx;
y=y+1-2*fy;
}
else
{
mciSendCommand (dev[0], MCI_CLOSE, NULL, NULL);
{
if(score%2==0)mciOpen.lpstrElementName="get1.mp3";
else mciOpen.lpstrElementName="get2.mp3";
if(mciSendCommand(NULL,MCI_OPEN, MCI_OPEN_ELEMENT ,(DWORD)&mciOpen)==0)
dev[0]=mciOpen.wDeviceID;
else
mciOpen.wDeviceID=dev[0];
mciPlay.dwFrom = 0;
mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,MCI_NOTIFY | MCI_FROM,(DWORD)&mciPlay);
}
x=x+1-2*fx;
y=y+1-2*fy;
score=score+a[y][x];
a[y][x]=0;
fy=1-fy;
fx=1-fx;
}
}
else if(y+1-2*fy<0)fy=1-fy;
else if(p+d>x && p-d=M)fy=1-fy;
else if(!(p+d>x && p-d=M)break;
else if(x+1-2*fx>=N || x+1-2*fx<0 )fx=1-fx;
}
if(sum==score)
{
printf("恭喜你,你淫了,再接再厉啊~\\(≧▽≦)/~\n");
mciSendCommand (dev[0], MCI_CLOSE, NULL, NULL);
{
mciOpen.lpstrElementName="win.mp3";
if(mciSendCommand(NULL,MCI_OPEN, MCI_OPEN_ELEMENT ,(DWORD)&mciOpen)==0)
dev[0]=mciOpen.wDeviceID;
else
mciOpen.wDeviceID=dev[0];
mciPlay.dwFrom = 0;
mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,MCI_NOTIFY | MCI_FROM,(DWORD)&mciPlay);
}
}
else
{
printf("真遗憾,你输了,下次注意啊Orz\n");
sum=0;score=0;
mciSendCommand (dev[0], MCI_CLOSE, NULL, NULL);
{
mciOpen.lpstrElementName="bang.wav";
if(mciSendCommand(NULL,MCI_OPEN, MCI_OPEN_ELEMENT ,(DWORD)&mciOpen)==0)
dev[0]=mciOpen.wDeviceID;
else
mciOpen.wDeviceID=dev[0];
mciPlay.dwFrom = 0;
mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,MCI_NOTIFY | MCI_FROM,(DWORD)&mciPlay);
}
}
printf("是否再来一次:\n1、是\t2、否\n");
c=getchar();
}
}