大例子二.docx
《大例子二.docx》由会员分享,可在线阅读,更多相关《大例子二.docx(36页珍藏版)》请在冰点文库上搜索。
大例子二
例子2
这是由我们小组当时为了应付课程的学习一起编的,同样是这个游戏,风格不同,取消了移动过程的动画,使得操作变灵活了,但是还是切忌狂按键盘,会过于灵敏。
此游戏最大亮点是有随机地图,增加了可玩性。
请适当改变TIME1和TIME2的定义数值,否则可能游戏进程过快。
老实说还是当初偷懒了,没用精确的时间控制。
提醒一下,切勿学习我们的编程风格。
效果图:
代码:
/*游戏:
吃豆子放P;
操作:
方向键移动,
空格键,放1型砸蛋,消耗10颗豆子,
V键放2型超级砸蛋,消耗25颗豆子,
胜利:
吃掉地图上全部豆子
失败:
被怪物抓住*/
#include
#include
#include
#include
#include
#include
#include
#defineTIME11000
#defineTIME23200
#defineAA15
#defineROW15
#defineCOL20
#defineSTARTX20
#defineSTARTY0
#defineSIZEX30
#defineSIZEY30
#defineROAD0
#defineDOU1
#defineWALL2
#defineSUIJI3/*随机参数*/
#defineENTER0x1c0d
#defineUP0x4800
#defineDOWN0x5000
#defineLEFT0x4b00
#defineRIGHT0x4d00
#defineESC0x011b
#defineSPACE0x3920
#defineLOWERV12150
intpi,pj;/*人物坐标*/
intp[2][20];/*怪的坐标*/
intdounum=0;
intnumbean;
intnumberbug;/*怪的数量*/
intbug[20];
intflag[ROW][COL];
intgameover=0;
intseed=1;
intxx=0;
intflag[ROW][COL]={2,2,0,0,2,2,0,0,0,2,0,2,0,2,2,0,2,0,2,0,
0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,2,0,0,0,0,0,0,2,0,0,2,2,0,0,0,0,2,2,
0,0,2,0,0,2,0,0,0,0,0,0,0,2,0,2,0,0,0,0,
0,0,0,0,2,0,0,2,0,2,0,2,0,0,0,0,0,0,2,2,
2,2,0,0,2,0,2,0,2,0,0,0,0,0,2,0,0,0,0,0,
2,0,0,0,0,0,0,0,0,0,2,0,2,0,0,0,2,2,0,2,
2,0,0,2,2,0,0,2,0,2,0,0,0,0,2,0,0,0,0,2,
0,0,2,0,0,0,2,0,0,0,0,2,0,0,2,0,0,2,0,0,
2,0,0,0,2,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,
0,0,2,0,0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,
2,0,0,0,2,0,0,2,0,0,0,0,0,0,2,0,0,2,0,2,
0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,2,0,0,2,0,0,2,0,0,2,0,0,2,0,0,0,2,0,2,
2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,};/*墙体基础分5层乱排的。
。
。
*/
intconfirm(intres);
voidmoveright();
voidmoveleft();
voidmoveup();
voidmovedown();
voidnewGame(intlevel);
voidmonstermove(intnumberbug);
voidinitGraph();
voiddrawBlock(inti,intj);
voiddrawBlock2(inti,intj);
intbomb1();
intbomb2();
voiddrawBlock3(inti,intj,intr);
voiddrawBlock4(inti,intj);
voiddrawBlock5(inti,intj);
intsuiji(intsed);
intgetKey(void);
voidmonstermove(intnumberbug);
voidmonstermove3(intnumberbug);
voidmonstermove2(intqx,intqy,intpi,intpj,inti);
voidmonstermove4(intqx,intqy,intpi,intpj,inti);
voidmonstermove4(intqx,intqy,intpi,intpj,inti){
intdir;
intmm,nn;
srand(seed++);/*种子每次要变,不然产生的随机数会相同*/
mm=rand()%15;/*取余数才能使坐标落在我游戏画面内*/
nn=rand()%20;
dir=judgedir(qx,qy,mm,nn);
switch(dir){
case1:
{drawBlock2(p[0][i],p[1][i]=p[1][i]-1);drawBlock2(p[0][i],p[1][i]+1);}break;
case2:
{drawBlock2(p[0][i]=p[0][i]-1,p[1][i]);drawBlock2(p[0][i]+1,p[1][i]);}break;
case3:
{drawBlock2(p[0][i]=p[0][i]+1,p[1][i]);drawBlock2(p[0][i]-1,p[1][i]);}break;
case4:
{drawBlock2(p[0][i],p[1][i]=p[1][i]+1);drawBlock2(p[0][i],p[1][i]-1);}break;
case0:
break;
}
}
voidmonstermove3(intnumberbug){
inti;
for(i=0;imonstermove4(p[0][i],p[1][i],pi,pj,i);
if(pi==p[0][i]&&pj==p[1][i]&&bug[i]!
=0)gameover=1;/*碰到怪就算输掉*/
}
}
intopen(){
inti,j,size;
intm=0,n=0,k=0;
void*buffer;
intgdriver=VGA,gmode=VGAHI,errorcode;
initgraph(&gdriver,&gmode,"");
clrscr();
/*以下一大片都是由本人写的开场动画,之前也展示过了*/
setfillstyle(1,6);
bar(0,0,640,480);
getchar();
setfillstyle(1,15);
fillellipse(320,240,70,70);
setcolor(0);
settextstyle(0,0,7);
settextjustify(1,1);
outtextxy(324,244,"3");
for(i=0;i<30;i++)
delay(2000);
for(i=0;i<361;i++){
setfillstyle(1,0);
pieslice(320,240,0,i,70);
delay(3000);
}
for(i=0;i<10;i++);
delay(5000);
setcolor(15);
settextstyle(0,0,7);
settextjustify(1,1);
outtextxy(324,244,"2");
for(i=0;i<30;i++)
delay(2000);
for(i=0;i<361;i++){
setfillstyle(1,15);
pieslice(320,240,0,i,70);
delay(3000);
}
for(i=0;i<10;i++)
delay(5000);
setcolor(0);
settextstyle(0,0,7);
settextjustify(1,1);
outtextxy(324,244,"1");
for(i=0;i<30;i++)
delay(2000);
setcolor(6);
for(i=0;i<361;i++){
setfillstyle(1,6);
pieslice(320,240,0,i+1,70);
delay(3000);
}
setcolor(0);
for(i=0;i<40;i++)
delay(5000);
for(i=0;i<320;i++){
setfillstyle(1,0);
bar(319-i,0,320-i,480);
bar(320+i,0,321+i,480);
delay(3000);
}
setfillstyle(1,0);
bar(0,0,40,40);
setcolor(0);
setfillstyle(1,2);
fillellipse(370,240,50,50);
setcolor(15);
setfillstyle(1,15);
fillellipse(370,220,10,10);
setfillstyle(1,0);
fillellipse(370,220,2,2);
pieslice(372,270,30,150,20);
setcolor
(2);
setfillstyle(1,2);
pieslice(372,287,30,150,30);
setcolor(0);
setfillstyle(1,14);
bar(366,251,369,255);
bar(373,251,376,255);
for(i=0;i<16;i++){
setfillstyle(1,14);
fillellipse(i*40+20,20,14,14);
}
for(i=0;i<16;i++){
setfillstyle(1,14);
fillellipse(i*40+20,460,14,14);
}
for(i=0;i<12;i++){
setfillstyle(1,14);
fillellipse(20,i*40+20,14,14);
}
for(i=0;i<12;i++){
setfillstyle(1,14);
fillellipse(620,i*40+20,14,14);
}
getchar();
setfillstyle(1,0);
bar(0,0,40,40);
setcolor(0);
setfillstyle(1,6);
pieslice(20,20,40,320,17);
for(i=0;i<600;i++){
j=i%60+1;
if(j<=30){
setfillstyle(1,6);
pieslice(20+i,20,40-j,320+j,17);
}
if(j>30){
setfillstyle(1,6);
pieslice(20+i,20,10+j-30,350-j+30,17);
}
delay(1000);
}
setfillstyle(1,0);
bar(600,0,640,40);
setfillstyle(1,6);
pieslice(620,20,0,230,17);
pieslice(620,20,310,360,17);
setcolor(6);
bar(620,19,636,21);
setcolor(0);
for(i=0;i<440;i++){
j=i%60+1;
if(j<=30){
setfillstyle(1,6);
pieslice(620,20+i,0,230+j,17);
pieslice(620,20+i,310-j,360,17);
setcolor(6);
bar(620,19+i,636,21+i);
setcolor(0);
}
if(j>30){
setfillstyle(1,6);
pieslice(620,20+i,0,260-j+30,17);
pieslice(620,20+i,280+j-30,360,17);
setcolor(6);
bar(620,19+i,636,21+i);
setcolor(0);
}
delay(1000);
}
setfillstyle(1,0);
bar(600,440,640,480);
setfillstyle(1,6);
pieslice(620,460,0,140,17);
pieslice(620,460,220,360,17);
setcolor(6);
bar(620,459,636,461);
setcolor(0);
for(i=0;i<600;i++){
j=i%60+1;
if(j<=30){
setfillstyle(1,6);
pieslice(620-i,460,0,140+j,17);
pieslice(620-i,460,220-j,360,17);
setcolor(6);
bar(620-i,459,636-i,461);
setcolor(0);
}
if(j>30){
setfillstyle(1,6);
pieslice(620-i,460,0,170-j+30,17);
pieslice(620-i,460,190+j-30,360,17);
setcolor(6);
bar(620-i,459,636-i,461);
setcolor(0);
}
delay(1000);
}
setfillstyle(1,0);
bar(0,440,40,480);
setfillstyle(1,6);
pieslice(20,460,0,50,17);
pieslice(20,460,130,360,17);
setcolor(6);
bar(20,459,36,461);
setcolor(0);
for(i=0;i<440;i++){
j=i%60+1;
if(j<=30){
setfillstyle(1,6);
pieslice(20,460-i,0,50+j,17);
pieslice(20,460-i,130-j,360,17);
setcolor(6);
bar(20,459-i,36,461-i);
setcolor(0);
}
if(j>30){
setfillstyle(1,6);
pieslice(20,460-i,0,80-j+30,17);
pieslice(20,460-i,100+j-30,360,17);
setcolor(6);
bar(20,459-i,36,461-i);
setcolor(0);
}
delay(1000);
}
setfillstyle(1,6);
pieslice(20,20,30,330,17);
for(i=0;i<210;i++){
setfillstyle(1,6);
pieslice(20+i,20,30,330,17);
delay(1000);
}
for(i=0;i<220;i++){
setfillstyle(1,6);
pieslice(230,20+i,30,330,17);
delay(1000);
}
for(i=0;i<33;i++){
setfillstyle(1,6);
pieslice(230,240,30,330,17+i);
delay(5000);
}
setfillstyle(1,0);
bar(0,0,290,290);
setfillstyle(1,6);
pieslice(230,240,30,330,60);
for(i=0;i<50;i++)
delay(5000);
setfillstyle(7,13);
bar(210,220,250,260);
for(i=0;i<180;i++){
setfillstyle(7,13);
bar(210-i,220-i,250+i,221-i);
bar(210-i,260+i,250+i,260+i);
bar(210-i,220-i,211-i,260+i);
bar(250+i,220-i,251+i,260+i);
delay(2000);
}
for(i=0;i<30;i++)
delay(5000);
setfillstyle(1,0);
bar(0,0,500,460);
setfillstyle(1,6);
pieslice(230,240,30,330,60);
for(i=0;i<90;i++){
setfillstyle(1,6);
pieslice(230+i,240,30,330,60);
delay(2000);
}
for(i=0;i<100;i++){
setfillstyle(8,9);
bar(0,480-i,640,477-i);
setfillstyle(8,4);
bar(0,0+i,640,3+i);
setfillstyle(8,7);
bar(0+i,0,3+i,480);
setfillstyle(8,3);
bar(637-i,0,640-i,480);
delay(2000);
}
setcolor(15);
settextstyle(3,0,4);
settextjustify(0,0);
outtextxy(265,150,"Team9");
for(i=0;i<30;i++)
delay(5000);
outtextxy(210,360,"Let'senjoyit!
");
for(i=0;i<=50;i++)
delay(5000);
getchar();
}
/*主函数在这里*/
intmain(){
intgameRes=0;
intlevel=1;
intkey;
ints=0;
inti;
open();
initGraph();
do{
newGame(level);
/*显示现在有的豆子数*/
setcolor(YELLOW);
writenumber(290,460,dounum);
gameRes=0;
gameover=0;
do{
for(i=0;i<50;i++){
delay(TIME2);
if(bioskey
(1)!
=0){
s=1;
break;
}
}
if(s==1){
s=0;
key=bioskey(0);
if(key==ESC)break;
switch(key){
caseLOWERV:
bomb2();break;
caseSPACE:
bomb1();break;
caseUP:
moveup();break;
caseDOWN:
movedown();break;
caseLEFT:
moveleft();break;
caseRIGHT:
moveright();break;
}
if(flag[pi][pj]==DOU){/*吃到豆子豆子数加1*/
dounum++;
numbean--;
flag[pi][pj]=ROAD;
}
/*显示现在有的豆子数*/
setcolor(YELLOW);
writenumber(290,460,dounum);
}
for(i=0;i<3;i++)
delay(5000);
if((xx++)%SUIJI==0)
monstermove(numberbug);
else
monstermove3(numberbug);
gameRes=checkWin();
}while(!
gameRes);
if(gameRes==1){level++;dounum=0;}
}while(!
confirm(gameRes));
return0;
}
intbomb1(){
if(dounum<10){return0;}
else{
dounum=dounum-10;}
/*覆盖显示的数字*/
setcolor(BLACK);
writenumber(290,460,dounum+10);
drawBlock3(pi,pj,3);
drawBlock4(pi-1,pj-1);
drawBlock4(pi-1,pj);
drawBlock4(pi-1,pj+1);
drawBlock4(pi,pj-1);
drawBlock4(pi,pj);
drawBlock4(pi,pj+1);
drawBlock4(pi+1,pj-1);
drawBlock4(pi+1,pj);
drawBlock4(pi+1,pj+1);
}
intbomb2(){
if(dounum<25)return0;
else{
dounum=dounum-25;}
/*覆盖显示的数字*/
setcolor(BLACK);
writenumber(290,460,dounum+25);
drawBlock3(pi,pj,5);
drawBlock4(pi-2,pj-2);
drawBlock4(pi-2,pj-1);
drawBlock4(pi-2,pj);
drawBlock4(pi-2,pj+1);
drawBlock4(pi-2,pj+2);
drawBlock4(pi-1,pj-2);
drawBlock4(pi-1,pj-1);
drawBlock4(pi-1,pj);
drawBlock4(pi-1,pj+1);
drawBlock4(pi-1,pj+2);
drawBlock4(pi,pj-2);
drawBlock4(pi,pj-1);
drawBlock4(pi,pj);
drawBlock4(pi,pj+1);
drawBlock4(pi,pj+2);
drawBlock4