学了好长时间C了,一直想做点什么,以前一直编一些很菜的游戏用来练手,暑假又做了一个16位图形处理系统,代码又长又烂,除了我没人能看懂,这些日子有按耐不住,编了这个简单的不能再简单的游戏,对初学者很有帮助!
#include<dos.h>
#include<graphics.h>
#include<stdio.h>
int x,y;
void doexit(),saveimage(),doimage(),imagedrive();
void *buff;
main()
{
int i,j,key;
int dokey();
char ch[]="BEAUIDEAL",c[]="help: right,down,left,up,enter,esc; very easy,OK!~!";
imagedrive();
saveimage();
cleardevice();
setbkcolor(7);
setcolor(1);
settextstyle(0,0,2);
outtextxy(250,50,ch);
setlinestyle(1,0,3);
rectangle(30,30,600,400);
setlinestyle(0,0,0);
settextstyle(0,0,1);
setcolor(8);
outtextxy(100,380,c);
setcolor(15);
for(i=0;i<5;i++)
for(j=0;j<5;j++)
rectangle(200+j*35,100+i*35,230+j*35,130+i*35);
setcolor(1);
rectangle(200,100,230,130);
x=200;
y=100;
while(1)
{
key=bioskey(0);
dokey(key);
}
free(buff);
closegraph();
}
void saveimage() /*存储方格*/
{
bar(0,0,29,29);
buff=sizeof(imagesize(0,0,29,29));
getimage(0,0,28,28,buff);
}
void imagedrive() /*图形模式初始化*/
{
int gd,gm;
gd=VGA;
gm=VGAHI;
initgraph(&gd,&gm,"");
cleardevice();
}
void doimage(x,y) /*画方格*/
{
void tell();
putimage(x+1,y+1,buff,1);
if(x!=200)
putimage(x+1-35,y+1,buff,1);
if(x!=340)
putimage(x+1+35,y+1,buff,1);
if(y!=100)
putimage(x+1,y+1-35,buff,1);
if(y!=240)
putimage(x+1,y+1+35,buff,1);
tell();
}
int dokey(key) /*键盘处理*/
int key;
{
int prect(),nrect();
switch(key)
{
case 0x4800 : if(y!=100) {prect(x,y);nrect(x,y-=35);} break;
case 0x4b00 : if(x!=200) {prect(x,y);nrect(x-=35,y);} break;
case 0x4d00 : if(x!=340) {prect(x,y);nrect(x+=35,y);} break;
case 0x5000 : if(y!=240) {prect(x,y);nrect(x,y+=35);} break;
case 0x11b : doexit();break;
case 0x1c0d : doimage(x,y);break;
}
}
void tell() /*判定是否画满*/
{
void win();
int color=15,t=0,i,j;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
if(color!=getpixel(215+i*35,115+j*35))
{t=1;break;}
if(t==0)
win();
}
void win()
{
char c;
settextstyle(3,0,2);
outtextxy(50,100,"YOU WIN !! do you want to replay (y/n) ");
do
{
c=getch();
if(c=='y'||c=='Y')
main(); /*从新玩就返回主函数*/
if(c=='n'||c=='N')
doexit();
}while(c=='y'||c=='Y'||c=='n'||c=='N');
}
int prect(x,y) /*在新位置画方框*/
{
setcolor(15);
rectangle(x,y,x+30,y+30);
}
int nrect(x,y) /*将原来位置的方框清除*/
{
setcolor(1);
rectangle(x,y,x+30,y+30);
}
void doexit()
{
free(buff);
closegraph();
exit(0);
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |