c语言局部清屏原理,问:怎样在图形模式下局部清屏?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

真惨!还是不行啊

我正在写个象棋的程序,我以为是Cover()出了问题,改了还是一样哦

你帮我看看吧

#include 

#include 

#include 

#include 

#include 

#include 

#include

#include

#define R 15

#define M 10

#define N 9

int board[M][N]={1,1,1,1,1,1,1,1,1,

0,0,0,0,0,0,0,0,0,

0,1,0,0,0,0,0,1,0,

1,0,1,0,1,0,1,0,1,

0,0,0,0,0,0,0,0,0,

0,0,0,0,0,0,0,0,0,

2,0,2,0,2,0,2,0,2,

0,2,0,0,0,0,0,2,0,

0,0,0,0,0,0,0,0,0,

2,2,2,2,2,2,2,2,2};

struct status{int x;int y;int x1;int y1; void *buffe;}loct[32];

Putmen(int a)

{int x,y,z,i,j=loct[a].y1,max,min,turn=1;

Cover(loct[a].x,loct[a].y);

board[loct[a].x1][loct[a].y1]=0;

for(i=loct[a].y1;board[loct[a].x1][i]<=0;i++)

max=i;

for(i=loct[a].y1;board[loct[a].x1][i]<=0;i--)

min=i;

do

{

mouse(&x,&y,&z);

if(xloct[a].x-18&&y>loct[a].y+40*(j-loct[a].y1)-18&&y<

loct[a].y+40*(j-loct[a].y1)+18&&board[loct[a].x1][j]!=1&&j

{putimage(loct[a].x,loct[a].y+40*(max-j),loct[a].buffe,0);loct[a].y=loc

t[a].y+40*(max-j);

loct[a].y1=j;

board[loct[a].x1][loct[a].y1]=1;turn=2;}

j++;

if(j==max)

{for(j=loct[a].y1;j>0;j--)

{if(xloct[a].x-18&&y>loct[a].y+40*(loct[a].y1-j)-18&&y

=min&&z==1)

{putimage(loct[a].x,loct[a].y+40*(j-min),loct[a].buffe,0);loct[a].y=loc

t[a].y+40*(j-min);

loct[a].y1=j;

board[loct[a].x1][loct[a].y1]=1;turn=2;}

}}

}while(turn==2);

}

Move()

{int x,y,z,i,j,turn=1;

do{

mouse(&x,&y,&z);

if(xloct[0].x-18&&yloct[0].y-18&&z==1

&&turn==1)

Putmen(0);

}while(x>450&&y>40&&x<495&&y>60);

}

Cover(int x,int y)

{setviewport(x-18,y-18,x+18,y+18,0);

clearviewport();

setcolor(RED);

line(x,y+18,x,y-18);

line(x-18,y,x+18,y);

}

getmouse(int *x,int *y,int *key)

{

union REGS inregs,outregs;

inregs.x.ax=3;

int86(0x33,&inregs,&outregs);

*x=outregs.x.cx;

*y=outregs.x.dx;

*key=outregs.x.bx;

}

void visbilemouse()

{

union REGS inregs,outregs;

inregs.x.ax=0x01;

int86(0x33,&inregs,&outregs);

}

mouse(int *x,int *y,int *z)

{int a=0,b=0,c=0,a_old=0,b_old=0;

int *ball;

ball=malloc(imagesize(a,b,a+R,b+R));

getimage(a,b,a+R,b+R,ball);

while(c==0)

{

getmouse(&a,&b,&c);

if(a<0) a=0;

if(b<0) b=0;

if(a>getmaxx()-R) a=getmaxx()-R;

if(b>getmaxy()-R) b=getmaxy()-R;

if(a!=a_old || b!=b_old)

{

putimage(a_old,b_old,ball,0);

getimage(a,b,a+R,b+R,ball);

setcolor(GREEN);

setlinestyle(0,0,1);

line(a,b,a+R,b+R/2);

line(a,b,a+R/2,b+R);

line(a+R,b+R/2,a+R/2,b+R);

line(a+R*3/4,b+R*3/4,a+R,b+R);

}

a_old=a;b_old=b;

}

*x=a;*y=b;*z=c;

putimage(a,b,ball,0);

free(ball);

}

Drawboard()

{int i,a;

int x=40;

char *q={"车马象士将士象马车"},*z={"车马相士帅士相马车"},

*qi={"卒"},*e={"兵"},*p={"炮"};

setbkcolor(0);

setcolor(RED);

rectangle(80,20,400,380);

setcolor(RED);

for(i=0;i<=7;i++,x+=40)

{ line(x+80,20,x+80,180);

line(x+80,380,x+80,220);

line(80,20+x,400,20+x);}

line(200,20,280,100);

line(200,100,280,20);

line(200,300,280,380);

line(200,380,280,300);

Drawman(75,20,1,q,2);

Drawman(75,380,1,z,5);

for(i=0,x=0;i<=4;i++,x+=80)

{

Drawman(x+75,140,0,qi,2);

Drawman(x+75,260,0,e,5);}

Drawman(115,300,0,p,5);

Drawman(355,300,0,p,5);

Drawman(115,100,0,p,2);

Drawman(355,100,0,p,2);

}

Drawcir(int x,int y)

{

setcolor(YELLOW);

setfillstyle(0,YELLOW);

circle(x,y,18);

circle(x,y,17);

floodfill(x,y,YELLOW);

}

Drawman(int x,int y,int z,char *s,int color)

{

FILE *fp;

char buffer[32];

int w=0;

register m,n,i,j,k;

unsigned char qh,wh;

unsigned long offset;

int ROW=1,COL=2;

fp=fopen("hzk16","rb");

while(*s)

{ Drawcir(x+5,y);

qh=*(s)-0xa0;

wh=*(s+1)-0xa0;

offset=(94*(qh-1)+(wh-1))*32L;

fseek(fp,offset,SEEK_SET);

fread(buffer,32,1,fp);

for (i=0;i<16;i++)

for(n=0;n

for(j=0;j<2;j++)

for(k=0;k<8;k++)

for(m=0;m

if (((buffer[i*2+j]>>(7-k))&0x1)!=NULL)

putpixel(x-10+8*j*COL+k*COL+m,y-10+i*ROW+n,color);

s+=2;

if(z) x+=40;

loct[w].buffe=malloc(imagesize(x-18,y-18,x+18,y+18));

getimage(x-18,y-18,x+18,y+18,loct[w].buffe);

w++;

}

}

Gamestart()

{

visbilemouse();

setcolor(WHITE);

rectangle(450,40,495,60);

outtextxy(460,45,"exit");

Move();

}

main()

{int gdriver=DETECT,gmode;

initgraph(&gdriver,&gmode,"c:\\TC");

cleardevice();

Drawboard();

Gamestart();

closegraph(); }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值