?? josepf.c
字號:
#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);
}
setfillstyle(1,BLACK);
bar(p->Per_B->X-15,p->Per_B->Y+15,p->Per_B->X+15,p->Per_B->Y+34);
putimage(p->Per_B->X-15,p->Per_B->Y+15,bitmap,XOR_PUT);
p->password=atoi(ch);
}while(p->password<=0);
free(bitmap);
}
Star_B_click()/*單擊開始按鈕*/
{
struct person *p,*frontp;
struct table *q;
int i=1;
p=PerHead.next;
frontp=PerHead.next;
while(frontp->next!=p)/*frontp指向p的前一結點*/
frontp=frontp->next;
q=T_Head.next;
while(1)
{ p->data=i;
DrawPer_B (p->Per_B,p);
Drawbasket(p->Per_B,frontp->Per_B );
if(p==frontp)
{ p->Per_B ->flag=0;
DrawPer_B (p->Per_B ,p);
setcolor(7);
circle(p->Per_B->X,p->Per_B->Y,PerR+1);
q->No=p->No;
p->password=0;
Drawtable(q);
Window1(p->No);
break;
}
if(i==M)
{ frontp->next=p->next;
M=p->password;
p->password=0;
q->No=p->No;
Drawtable(q);
q=q->next;
p->Per_B ->flag=0;
DrawPer_B (p->Per_B ,p);
Window1(p->No);
setcolor(7);
circle(p->Per_B ->X,p->Per_B ->Y,PerR+1);
free(p);
p=frontp->next;
i=1; }
else
{ i++;
p=p->next;
frontp=frontp->next; }
}
}
Window1(int i)/*彈出該人出列的提示信息*/
{ void *bitmap;
int Left=240,top=220,right=400,low=280;
char ch[20];
struct Button C_B = {280 ,250,360,270,1,"continue"};
bitmap=malloc(imagesize(Left,top,right,low));
getimage(Left,top,right,low,bitmap);
putimage(Left,top,bitmap,XOR_PUT);
setcolor(6);
rectangle(Left,top,right,low);
setfillstyle(1,7);
bar(Left+1,top+1,right-1,low-1);
Draw_B (C_B.Left,C_B.top,C_B.right,C_B.low,&C_B );
sprintf(ch,"No.%d Out!",i);
setcolor(BLACK);
outtextxy(Left+18,top+15,ch);
while(1)
{ key=0;
if(kbhit())
key=bioskey(0);
if(key == 0x1c0d) break;
}
setfillstyle(1,BLACK);
bar(Left,top,right,low);
putimage(Left,top,bitmap,XOR_PUT);
free(bitmap);
}
Window2()
{ void *bitmap;
int Left=240,top=220,right=400,low=280;
char ch[20];
struct Button Exit_B={290,250,340,270,1,"EXIT"};
bitmap=malloc(imagesize(Left,top,right,low));
getimage(Left,top,right,low,bitmap);
putimage(Left,top,bitmap,XOR_PUT);
setcolor(6);
rectangle(Left,top,right,low);
setfillstyle(1,7);
bar(Left+1,top+1,right-1,low-1);
Draw_B(Exit_B.Left,Exit_B.top,Exit_B.right,Exit_B.low,&Exit_B);
setcolor(0);
outtextxy(Left+18,top+15,"All person Out!");
getch();
while(1)
{ key=0;
if(kbhit())
key=bioskey(0);
if(key == 0x1c0d); break;
}
setfillstyle(1,BLACK);
bar(Left,top,right,low);
putimage(Left,top,bitmap,XOR_PUT);
free(bitmap);
}
IfOnlyOne()/*判斷每個人是否都有一個密碼*/
{ struct person *p;
p=PerHead.next;
do
{ if(p->password==0) return 0;
else p=p->next;
}
while(p!=PerHead.next);
return 1;
}
Initbkground()
{ clrscr();
Initgraph ();
InitMS();
Set_M(0,0,619,479);
Map=malloc( imagesize(0,0,M_S,M_S) );
setfillstyle(1,7);
bar(1,1,20,20);
setfillstyle(1,BROWN);
bar(21,1,639,20);
setcolor(0);
outtextxy(290,6,"Welcome!");
setfillstyle(1,7);
bar(0,21,639,479);
setcolor(BROWN);
rectangle(0,0,639,479);
line(0,60,639,60);
line(0,400,639,400);
setcolor(RED);
outtextxy(10,410,"OutPerson:");
}
star()
{ struct person *p;
int flag=0;
int i;
Initbkground();
Draw_B (End_B.Left,End_B.top,End_B.right,End_B.low,&End_B);
Draw_B (InputN_B.Left,InputN_B.top,InputN_B.right,InputN_B.low,&InputN_B);
Draw_B (InputM_B.Left,InputM_B.top,InputM_B.right,InputM_B.low,&InputM_B );
Draw_B (Star_B.Left,Star_B.top,Star_B.right,Star_B.low,&Star_B );
while(1)
{ key=0;
if(kbhit())
key=bioskey(0);
if(key == 0x11b)
break;
M_Position();
putimage(x,y,Map,COPY_PUT);
x=M_X;
y=M_Y;
if(M_Key==1)
{ flag=IfOnlyOne();
if(End_B.Left<=M_X&&M_X<=End_B.right&&End_B.top<=M_Y&&M_Y<=End_B.low)
break;
else if(InputN_B.Left<=M_X&&M_X<=InputN_B.right&&InputN_B.top<=M_Y&&M_Y<=InputN_B.low&&InputN_B.Entered ==1)
{
while(N<=0||N>100)
InputN_B_click();
Init_Per ();
Init_OutPer();
Draw_B (InputN_B.Left,InputN_B.top,InputN_B.right,InputN_B.low,&InputN_B);
Draw_B (InputM_B.Left,InputM_B.top,InputM_B.right,InputM_B.low,&InputM_B );
}
else if(InputM_B.Left<=M_X&&M_X<=InputM_B.right&&InputM_B.top<=M_Y&&M_Y<=InputM_B.low&&InputM_B .Entered ==1)
{
while(M<=0)
InputM_B_click();
Draw_B (InputM_B.Left,InputM_B.top,InputM_B.right,InputM_B.low,&InputM_B );
Draw_B (Star_B.Left,Star_B.top,Star_B.right,Star_B.low,&Star_B );
}
else if(Star_B.Left<=M_X&&M_X<=Star_B.right&&Star_B.top<=M_Y&&M_Y<=Star_B.low&&Star_B .Entered ==1&&flag==1)
{
Star_B .Entered =0;
End_B.Entered =0;
Draw_B (Star_B.Left,Star_B.top,Star_B.right,Star_B.low,&Star_B );
Draw_B (End_B.Left,End_B.top,End_B.right,End_B.low,&End_B);
Star_B_click();
End_B.Entered =1;
Draw_B (End_B.Left,End_B.top,End_B.right,End_B.low,&End_B);
Window2();
break;
}
else if(InputN_B.Entered ==0)
{
p=PerHead.next;
do
{ if(p->Per_B->X-15<=M_X&&M_X<=p->Per_B->X+15&&p->Per_B->Y-15<=M_Y&&M_Y<=p->Per_B->Y+15)
{ Per_B_click(p);
DrawPer_B(p->Per_B,p);
break; }
else p=p->next;
}while(p!=PerHead.next);
}
else
;
}
getimage(M_X,M_Y,M_X+M_S,M_Y+M_S,Map);
Draw_M(M_X,M_Y); }
}
main()
{ clrscr();
Initgraph();
setbkcolor(7);
setcolor(6);
line(30,400,600,400);
outtextxy(200,200,"Welcome to the show of josepf");
outtextxy(5,380, "Press any key to continue...");
getch();
star();
clrscr();
Initgraph();
setbkcolor(7);
setcolor(6);
outtextxy(200,200, "Thanks for you come here!");
outtextxy(230,220, "You are welcome!");
outtextxy(260,240, "Byebye!");
line(30,400,600,400);
outtextxy(200,420, "Maker:xie shi long");
outtextxy(200,440, "Mobile:13855327123");
outtextxy(200,460, "Email:hardhope@163.com");
outtextxy(5,380,"Press any key to exit...");
getch(); exit(0);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -