/*磁盘记录方式模拟(RZ方式) */
#include "graphics.h"
#include "conio.h"
#include "stdio.h"
#include "ctype.h"
void linex(int i,int g,int j,int k,int l)
{
int m;
if(i<j)
for(m=i;m<j;m++)
{
line(m,g,m+1,k);
delay(l);
}
else
for(m=i;m>j;m--)
{
line(m,g,m-1,k);
delay(l);
}
}
void liney(int g,int i,int k,int j,int l)
{
int m;
if(i<j)
for(m=i;m<j;m++)
{
line(g,m,k,m+1);
delay(l);
}
else
for(m=i;m>j;m--)
{
line(g,m,k,m-1);
delay(l);
}
}
void linehshsh(int h,int i,int j,int k,int l,int m,int n,int g)
{
linex(h,i,j,i,g);
liney(j,i,j,k,g);
linex(j,k,l,k,g);
liney(l,k,l,m,g);
linex(l,m,n,m,g);
}
void outtextxys(int i,int j,int k)
{
int m,n;
if(k<10)
switch(k)
{
case 1:
outtextxy(i,j,"1");
break;
case 2:
outtextxy(i,j, "2");
break;
case 3:
outtextxy(i,j,"3");
break;
case 4:
outtextxy(i,j, "4");
break;
case 5:
outtextxy(i,j,"5");
break;
case 6:
outtextxy(i,j, "6");
break;
case 7:
outtextxy(i,j,"7");
break;
case 8:
outtextxy(i,j, "8");
break;
case 9:
outtextxy(i,j,"9");
break;
default:
outtextxy(i,j, "0");
}
else
{
m=k/10;
n=k%10;
outtextxys(i,j, m);
outtextxys(i+5,j,n);
}
}
main( )
{
int graphdriver=DETECT,graphmode;
int i,j,l,h,m,n,a[17],b;
/* registerbgidriver(EGAVGA_driver); */
initgraph(&graphdriver,&graphmode,"");
start: cleardevice();
m=75;n=180;h=32;
gotoxy(6,3);
printf("Choose (1:Single;2:Whole):");
setcolor(CYAN);
line(248,48,255,48);
gotoxy(6,14);
printf("RZ:");
for(i=0;i<=16;i++)
{
setcolor(WHITE);
for(j=0;j<80;j+=5)
liney(m+i*h,n+j,m+i*h,n+j+2,0);
if(i!=16)
{
for(j=0;j<30;j+=5)
linex(m+i*h+j,n+m/2,m+i*h+j+2,n+m/2,0);
setcolor(CYAN);
linex(m+i*h+4,n-3,m+(i+1)*h-4,n-3,0);
linex(m+i*h+4,n-30,m+(i+1)*h-4,n-30,0);
setcolor(RED);
settextstyle(0,0,0);
settextjustify(1,0);
outtextxys(m+i*h+15,n-30,i+1);
}
}
gotoxy(50,24);
printf("1: Quit 2: return :");
setcolor(CYAN);
line(545,385,552,385);
gotoxy(32,3);
scanf("%d",&l);
setcolor(RED);
switch(l)
{
case 1:{
gotoxy(6,7);
printf("input code:");
for(i=0;i<16;i++)
{
gotoxy(12+i*4,11);
a=getch();
if((a!='1')&&(a!='0')) break;
gotoxy(12+i*4,11);
printf("%c",a);
if(a=='1')
linehshsh(m+i*h,n+37,m+i*h+11,n+10,m+i*h+21,n+37,m+(i+1)*h,800);
else if(a=='0')
linehshsh(m+i*h,n+37,m+i*h+11,n+70,m+i*h+21,n+37,m+(i+1)*h,800);
}
break;
}
case 2:
{
j=0;
gotoxy(6,7);
printf("input code(the length <= 16):");
for(i=0;i<16;i++)
{
line(272+i*6+j,112,272+(i+1)*6+j,112);
j+=2;
}
i=0;
gotoxy(35,7);
do{
a=getch();
if((a!='1')&&(a!='0')) break;
gotoxy(35+i,7);
printf("%c",a);
i++;
}while(1);
a='\0';
j=0;
do{
gotoxy(12+j*4,11);
printf("%c",a[j]);
j++;
}while(a[j]!='\0');
for(i=0;i<j;i++)
{
if(a=='1')
linehshsh(m+i*h,n+37,m+i*h+11,n+10,m+i*h+21,n+37,m+(i+1)*h,800);
else if(a=='0')
linehshsh(m+i*h,n+37,m+i*h+11,n+70,m+i*h+21,n+37,m+(i+1)*h,800);
}
break;
}
}
gotoxy(69,24);
j=getch();
gotoxy(69,24);
printf("%c",j);
if(j=='2')
{ getch();
goto start;
}
getch();
closegraph();
}