这是我用C编的第一个大点的程序
结构和注释都不太好
但功能已经能实现了,请大家指点一下:
游戏任务:
找到画面上的十个小旗!
玩法:
1:可用方向键移动人
2:可以推开箱子
3:有十个炸弹,可炸掉周围的箱子,并有可能,爆出炸弹,捡起可以增加炸弹数
4:按esc,出现退出提示时,按N键退出
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<bios.h>
#define ESC 0x011b
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ENTER 0x1c0d
#define MX 28
#define MY 24
#define BOXLONG 20
#define SQI 10
#define SZADAN 10
struct point
{
int x;
int y;
}zaboxxy[4]={-1,0,1,0,0,-1,0,1};
int x,y,map[MX+1][MY+1],szadan,sqi,szuan=0,mx,my,mc;
void *tx[5];
char sc[10];
/******************************
change a intnumber to a char []
*******************************/
char *ntos(int n, char *c)
{long i=0,j,k;
for(j=5;j>=0;j--)
{k=n/pow(10,j);
if(k>0||n==0)
{c[i++]=k+'0';
n=n-k*pow(10,j);}
}
c[i]=0;
return©;
}
main()
{
int dr=DETECT,mode=0,i;
long key=0;
initgraph(&dr,&mode,"");
mx=getmaxx();
my=getmaxy();
mc=getmaxcolor();
for(i=1;i<5;i++) tx[i]=malloc(imagesize(1,1,BOXLONG,BOXLONG));
loadmap();
again:
gamemessage();
sqi=SQI;szadan=SZADAN;
definemap();
do
{ while(bioskey(1)==0);
key=bioskey(0);
move(key);
}while(key!=ESC && sqi>0);
if(sqi==0)message("you are winer!!!!");
if(message("do you want play again ?")==1)goto again;
for(i=1;i<5;i++) free(tx[i]);
closegraph();
}
/*******************
SEND A message
*******************/
int message(char *s)
{ char c;
setfillstyle(1,4);
setcolor(1);
bar(mx/2-200,my/2-50,mx/2+250,my/2+50);
outtextxy(mx/2-200,my/2-20,s);
c=getch();
if(c=='n'|| c=='N')return(0);else return(1);
}
/*******************
draw map
*******************/
loadmap()
{
cleardevice();
setcolor(1);
rectangle(1,1,BOXLONG,BOXLONG);
setcolor(3);
setfillstyle(1,4);
bar(5,3,6,18);
setcolor(4);
line(6,3,15,13);
line(6,13,15,13);
floodfill(14,12,4);
getimage(1,1,BOXLONG,BOXLONG,tx[1]);
putimage(1,1,tx[1],1);
setcolor(4);
rectangle(1,1,BOXLONG,BOXLONG);
circle(10,10,9);
circle(5,5,3);
circle(15,5,3);
line(8,15,12,15);
getimage(1,1,BOXLONG,BOXLONG,tx[2]);
putimage(1,1,tx[2],1);
setcolor(1);
setfillstyle(1,4);
bar(1,1,BOXLONG,BOXLONG);
line(1,BOXLONG/3,BOXLONG,BOXLONG/3);
line(1,BOXLONG/3*2,BOXLONG,BOXLONG/3*2);
line(BOXLONG/2,1,BOXLONG/2,BOXLONG/3);
line(BOXLONG/2,BOXLONG/3*2,BOXLONG/2,BOXLONG);
line(BOXLONG/3,BOXLONG/3,BOXLONG/3,BOXLONG/3*2);
line(BOXLONG/3*2+2,BOXLONG/3,BOXLONG/3*2+2,BOXLONG/3*2);
getimage(1,1,20,20,tx[3]);
putimage(1,1,tx[3],1);
rectangle(1,1,BOXLONG,BOXLONG);
setcolor(4);
circle(10,10,6);
line(10,3,10,5);
getimage(1,1,BOXLONG,BOXLONG,tx[4]);
putimage(1,1,tx[4],1);
}
/*******************
random map
*******************/
definemap()
{int i,j,x1,y1,x2[SQI+1],y2[SQI+1];
randomize();
for (i=0;i<=MX;i++)
for (j=0;j<=MY;j++)
map[i][j]=0;
cleardevice();
结构和注释都不太好
但功能已经能实现了,请大家指点一下:
游戏任务:
找到画面上的十个小旗!
玩法:
1:可用方向键移动人
2:可以推开箱子
3:有十个炸弹,可炸掉周围的箱子,并有可能,爆出炸弹,捡起可以增加炸弹数
4:按esc,出现退出提示时,按N键退出
#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<bios.h>
#define ESC 0x011b
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define ENTER 0x1c0d
#define MX 28
#define MY 24
#define BOXLONG 20
#define SQI 10
#define SZADAN 10
struct point
{
int x;
int y;
}zaboxxy[4]={-1,0,1,0,0,-1,0,1};
int x,y,map[MX+1][MY+1],szadan,sqi,szuan=0,mx,my,mc;
void *tx[5];
char sc[10];
/******************************
change a intnumber to a char []
*******************************/
char *ntos(int n, char *c)
{long i=0,j,k;
for(j=5;j>=0;j--)
{k=n/pow(10,j);
if(k>0||n==0)
{c[i++]=k+'0';
n=n-k*pow(10,j);}
}
c[i]=0;
return©;
}
main()
{
int dr=DETECT,mode=0,i;
long key=0;
initgraph(&dr,&mode,"");
mx=getmaxx();
my=getmaxy();
mc=getmaxcolor();
for(i=1;i<5;i++) tx[i]=malloc(imagesize(1,1,BOXLONG,BOXLONG));
loadmap();
again:
gamemessage();
sqi=SQI;szadan=SZADAN;
definemap();
do
{ while(bioskey(1)==0);
key=bioskey(0);
move(key);
}while(key!=ESC && sqi>0);
if(sqi==0)message("you are winer!!!!");
if(message("do you want play again ?")==1)goto again;
for(i=1;i<5;i++) free(tx[i]);
closegraph();
}
/*******************
SEND A message
*******************/
int message(char *s)
{ char c;
setfillstyle(1,4);
setcolor(1);
bar(mx/2-200,my/2-50,mx/2+250,my/2+50);
outtextxy(mx/2-200,my/2-20,s);
c=getch();
if(c=='n'|| c=='N')return(0);else return(1);
}
/*******************
draw map
*******************/
loadmap()
{
cleardevice();
setcolor(1);
rectangle(1,1,BOXLONG,BOXLONG);
setcolor(3);
setfillstyle(1,4);
bar(5,3,6,18);
setcolor(4);
line(6,3,15,13);
line(6,13,15,13);
floodfill(14,12,4);
getimage(1,1,BOXLONG,BOXLONG,tx[1]);
putimage(1,1,tx[1],1);
setcolor(4);
rectangle(1,1,BOXLONG,BOXLONG);
circle(10,10,9);
circle(5,5,3);
circle(15,5,3);
line(8,15,12,15);
getimage(1,1,BOXLONG,BOXLONG,tx[2]);
putimage(1,1,tx[2],1);
setcolor(1);
setfillstyle(1,4);
bar(1,1,BOXLONG,BOXLONG);
line(1,BOXLONG/3,BOXLONG,BOXLONG/3);
line(1,BOXLONG/3*2,BOXLONG,BOXLONG/3*2);
line(BOXLONG/2,1,BOXLONG/2,BOXLONG/3);
line(BOXLONG/2,BOXLONG/3*2,BOXLONG/2,BOXLONG);
line(BOXLONG/3,BOXLONG/3,BOXLONG/3,BOXLONG/3*2);
line(BOXLONG/3*2+2,BOXLONG/3,BOXLONG/3*2+2,BOXLONG/3*2);
getimage(1,1,20,20,tx[3]);
putimage(1,1,tx[3],1);
rectangle(1,1,BOXLONG,BOXLONG);
setcolor(4);
circle(10,10,6);
line(10,3,10,5);
getimage(1,1,BOXLONG,BOXLONG,tx[4]);
putimage(1,1,tx[4],1);
}
/*******************
random map
*******************/
definemap()
{int i,j,x1,y1,x2[SQI+1],y2[SQI+1];
randomize();
for (i=0;i<=MX;i++)
for (j=0;j<=MY;j++)
map[i][j]=0;
cleardevice();