#include "stdlib.h"
#include "graphics.h"
#include "dos.h"
#define M_S 20
#define Per_Max 100
#define OutPerLeft 10
#define OutPertop 430
#define OutPerLength 32
#define OutPerWide 10
#define PerX 45
#define PerY 85
#define PerR 15
struct person
{ int No;
int data;
int password;
struct Per_B *Per_B ;
struct person *next;
}PerHead;
struct Per_B
{ int X,Y,R;
int flag;
};
struct table
{ int Left,top,right,low;
int No;
char ch[5];
struct table *next;
}T_Head;
struct Button
{ int Left,top,right,low;
int Entered ;
char ch[10];
};
struct Text
{ int Left,top,right,low;
char ch[10];
};
union REGS regs;
void *Map;
int M_X,M_Y;
int M_Key;
int x=0,y=0;
int key;
int N,M;
struct Button End_B= {1 ,1 ,20 ,20 ,1,"X"};
struct Button InputN_B= {30 ,30 ,100,50 ,1,"Input N"};
struct Button InputM_B = {120,30 ,190,50 ,0,"Input M"};
struct Button Star_B ={210,30 ,280,50 ,0,"star"};
struct Text InputN_T={30,50,80,69,""};
struct Text InputM_T={120,50,170,69,""};
Initgraph()/*图形模式初始化*/
{
int gd=DETECT,gm;
registerbgidriver(EGAVGA_driver);/*在Tc环境运行中,如若不能运行,可将此语句屏蔽掉*/
initgraph(&gd,&gm,"");
}
InitMS()/*鼠标初始化*/
{
regs.x.ax=0;
int86(0x33,®s,®s);
}
Draw_M(int x,int y)/*画鼠标*/
{
setcolor(15);
line(x ,y ,x ,y+20);
line(x ,y ,x+20 ,y );
line(x+5 ,y+5,x ,y+20);
line(x+5 ,y+5,x+20 ,y );
}
M_Position()/*读取鼠标移动,按键情况*/
{
int x0=M_X,y0=M_Y,password0=M_Key;
do
{
regs.x.ax=3;
int86(0x33,®s,®s);
M_X=regs.x.cx;
M_Y=regs.x.dx;
M_Key =regs.x.bx;
}while(M_X==x0&&M_Y==y0&&M_Key ==password0);
}
Set_M(int x1,int y1,int x2,int y2)/*设置鼠标的移动范围,x0,y0为左上角的坐标,x1,y1右下角的坐标*/
{
regs.x.cx=x1;
regs.x.dx=x2;
regs.x.ax=7;
int86(0x33,®s,®s);
regs.x.cx=y1;
regs.x.dx=y2;
regs.x.ax=8;
int86(0x33,®s,®s);
}
Init_Per ()/*建立有N个人的一个循环链表*/
{
int i;
struct person *q,*p;
PerHead.No=0;
PerHead.data=0;
PerHead.password=0;
PerHead.Per_B =NULL;
PerHead.next=&PerHead;
p=&PerHead;
for(i=1;i<=N;i++)
{ q=(struct person *)malloc(sizeof(struct person));
q->No=i;
q->data=0;
q->password=i;
q->Per_B =(struct Per_B*)malloc(sizeof(struct Per_B ));
q->Per_B ->X=PerX+(i-1)%10*(2*PerR+10);
q->Per_B ->Y=PerY+(i-1)/10*(2*PerR+10);
q->Per_B ->flag=1;
DrawPer_B (q->Per_B ,q);
p->next=q;
q->next=PerHead.next;
p=p->next; }
}
Init_OutPer()/*建立存储N个人出列顺序的链表*/
{ int i;
struct table *q,*p;
T_Head.Left=T_Head.top=T_Head.right=T_Head.low=0;
T_Head.No=0;
strcpy(T_Head.ch,"");
T_Head.next=NULL;
p=&T_Head;
for(i=1;i<=N;i++)
{ q=(struct table *)malloc(sizeof(struct table));
q->No=0;
strcpy(q->ch,"");
q->Left=OutPerLeft+(i-1)%20*OutPerLength;
q->top=OutPertop+(i-1)/20*OutPerWide;
q->right=q->Left+OutPerLength;
q->low=q->top+OutPerWide;
p->next=q;
q->next=NULL;
p=p->next; }
p=T_Head.next;
while(p!=NULL)
{ Drawtable(p);
p=p->next; }
}
DrawText(int Left,int top,int right,int low)
{ setcolor(6);
rectangle(Left, top, right, low);
setfillstyle(1, WHITE);
bar(Left+1,top+1,right-1,low-1);
}
Drawtable(struct table *p)/*画表示结果的标签*/
{
sprintf(p->ch,"%d",p->No);
setcolor(BROWN);
rectangle(p->Left,p->top,p->right,p->low);
setfillstyle(1, 7);
bar (p->Left+1,p->top+1,p->right-1,p->low-1);
setcolor(BLACK);
outtextxy(p->Left+2,p->top+2,p->ch);
}
Drawbasket(struct Per_B *p,struct Per_B *q)
{
setcolor(7);
circle(q->X,q->Y,PerR+1);
setcolor(14);
circle(p->X,p->Y,PerR+1);
}
Draw_B (int Left,int top,int right,int low,struct Button *p)
{ setcolor(6);
rectangle(Left, top, right, low);
if(p->Entered )
{ setcolor(BLACK);
outtextxy(p->Left+6,p->top+6,p->ch); }
else
{ setcolor(WHITE);
outtextxy(p->Left+6,p->top+6,p->ch); }
}
DrawPer_B(struct Per_B *p,struct person *q)
{
char data[4];
char password[4];
sprintf(data,"%d",q->data);
sprintf(password,"%d",q->password);
setfillstyle(1,7);
bar(p->X-10,p->Y-10,p->X+10,p->Y+10);
setcolor(6);
circle(p->X,p->Y,PerR);
setcolor(4);
line(p->X-14,p->Y,p->X+14,p->Y);
if(p->flag==0)
{ setcolor(8);
setfillstyle(1, 8);
floodfill(p->X,p->Y,6); }
setcolor(RED);
outtextxy(p->X-5,p->Y-10 ,data);
setcolor(BLACK);
outtextxy(p->X-4,p->Y+4,password);
}
InputN_B_click()
{ void *bitmap;
int i;
bitmap=malloc(imagesize(InputN_T.Left,InputN_T.top,InputN_T.right,InputN_T.low));
getimage(InputN_T.Left,InputN_T.top,InputN_T.right,InputN_T.low,bitmap);
putimage(InputN_T.Left,InputN_T.top,bitmap,XOR_PUT);
DrawText(InputN_T.Left,InputN_T.top,InputN_T.right,InputN_T.low);
for(i=0;i<3;i++)
{ InputN_T.ch[i]=getch();
if(InputN_T.ch[i]==8)
{ i=i-2;
if(i<-1)
i=-1;
}
if(InputN_T.ch[i]==13)
{ InputN_T.ch[i]='\0';
break;
}
InputN_T.ch[i+1]='\0';
setfillstyle(1,WHITE);
bar(InputN_T.Left+5,InputN_T.top+6,InputN_T.right-5,InputN_T.low-6);
setcolor(1);
outtextxy(InputN_T.Left+5,InputN_T.top+6,InputN_T.ch);
}
setfillstyle(1,BLACK);
bar(InputN_T.Left,InputN_T.top,InputN_T.right,InputN_T.low);
putimage(InputN_T.Left,InputN_T.top,bitmap,XOR_PUT);
N=atoi(InputN_T.ch);
InputN_B.Entered =0;
InputM_B .Entered =1;
}
InputM_B_click()
{ void *bitmap;
int i;
bitmap=malloc(imagesize(InputM_T.Left,InputM_T.top,InputM_T.right,InputM_T.low));
getimage(InputM_T.Left,InputM_T.top,InputM_T.right,InputM_T.low,bitmap);
putimage(InputM_T.Left,InputM_T.top,bitmap,XOR_PUT);
DrawText(InputM_T.Left,InputM_T.top,InputM_T.right,InputM_T.low);
for(i=0;i<3;i++)
{ InputM_T.ch[i]=getch();
if(InputM_T.ch[i]==8)
{ i=i-2;
if(i<-1)
i=-1;
}
if(InputM_T.ch[i]==13)
{ InputM_T.ch[i]='\0';
break;
}
InputM_T.ch[i+1]='\0';
setfillstyle(1,WHITE);
bar(InputM_T.Left+5,InputM_T.top+6,InputM_T.right-5,InputM_T.low-6);
setcolor(1);
outtextxy(InputM_T.Left+5,InputM_T.top+6,InputM_T.ch);
}
setfillstyle(1,BLACK);
bar(InputM_T.Left,InputM_T.top,InputM_T.right,InputM_T.low);
putimage(InputM_T.Left,InputM_T.top,bitmap,XOR_PUT);
M=atoi(InputM_T.ch);
InputM_B.Entered =0;
Star_B.Entered =1;
}
Per_B_click(struct person *p)
{ void *bitmap;
int i;
char ch[4];
bitmap=malloc(imagesize(p->Per_B->X-15,p->Per_B->Y+15,p->Per_B->X+15,p->Per_B->Y+34));
getimage(p->Per_B->X-15,p->Per_B->Y+15,p->Per_B->X+15,p->Per_B->Y+34,bitmap);
do
{ putimage(p->Per_B->X-15,p->Per_B->Y+15,bitmap,XOR_PUT);
DrawText(p->Per_B->X-15,p->Per_B->Y+15,p->Per_B->X+15,p->Per_B->Y+34);
for(i=0;i<3;i++)
{ ch[i]=getch();
if(ch[i]==8)
{ i=i-2;
if(i<-1)
i=-1;
}
if(ch[i]==13)
{ ch[i]='\0';
break;
}
ch[i+1]='\0';
setfillstyle(1,WHITE);
bar(p->Per_B->X-15+2,p->Per_B->Y+15+3,p->Per_B->X+15-2,p->Per_B->Y+34-3);
setcolor(1);
outtextxy(p->Per_B->X-15+5,p->Per_B->Y+15+6,ch);
评论0