www.pudn.com > c.rar > JUANPAN.C, change:1980-01-01,size:3370b


#include "graphics.h" 
#include "stdlib.h" 
#include "stdio.h" 
#include "conio.h" 
#include "math.h" 
#define UP 72 
#define DOWN 80 
#define LEFT 75 
#define RIGHT 77 
#define ESC 27 
int disk[4][8]; 
int main(void) 
{ 
int gdrive=DETECT,gmode; 
int midx,midy; 
int ag[4],diskid=0; 
int cc; 
initgraph(&gdrive,&gmode,""); 
get_disk(ag,disk); 
midx=getmaxx()/2;midy=getmaxy()/2; 
do{ 
if(diskid<0)diskid=3; 
else if (diskid>3)diskid=0; 
index(midx,midy,diskid); 
cc=getch(); 
switch(cc){ 
case UP:diskid++;break; 
case DOWN:diskid--;break; 
case RIGHT: 
rotate_disk(disk,midx,midy,ag,diskid,-1); 
ag[diskid]-=1; 
if(ag[diskid]<0)ag[diskid]=7; 
draw_disk_cross(midx,midy,diskid); 
break; 
case LEFT: 
rotate_disk(disk,midx,midy,ag,diskid,1); 
ag[diskid]+=1; 
if(ag[diskid]>7)ag[diskid]=0; 
draw_disk_cross(midx,midy,diskid); 
break; 
case 'h': 
draw_a_disk(disk,midx/2,midy/2,100,7,0,1,0); 
draw_a_disk(disk,midx/2,midy/2,80,BLUE,0,1,1); 
draw_a_disk(disk,midx/2,midy/2,60,RED,0,1,2); 
draw_a_disk(disk,midx/2,midy/2,40,GREEN,0,1,3); 
break; 
} 
} 
while(cc!=ESC&&!done(ag)); 
closegraph(); 
return 0;} 
 
/***********************************************************/ 
get_disk(int ag[4],int disk[4][8]) 
{ 
int i,j,midx,midy; 
randomize(); 
ag[0]=random(8); 
do ag[1]=random(8); 
while (ag[1]==ag[0]); 
do ag[2]=random(8); 
while((ag[2]==ag[0])||(ag[2]==ag[1])); 
do ag[3]=random(8); 
while((ag[3]==ag[0])||(ag[3]==ag[1])||(ag[3]==ag[2])); 
for(j=0;j<8;j++) 
{do {disk[0][j]=random(5)+1; 
disk[1][j]=random(5)+1; 
disk[2][j]=random(5)+1; 
disk[3][j]=12-disk[0][j]-disk[1][j]-disk[2][j]; 
} 
while (disk[3][j]<1||disk[3][j]>5); 
} 
midx=getmaxx()/2; 
midy=getmaxy()/2; 
draw_a_disk(disk,midx,midy,100,7,ag[0]*45,1,0); 
draw_a_disk(disk,midx,midy,80,BLUE,ag[1]*45,1,1); 
draw_a_disk(disk,midx,midy,60,RED,ag[2]*45,1,2); 
draw_a_disk(disk,midx,midy,40,GREEN,ag[3]*45,1,3); 
} 
done(int ag[4]) 
{ 
int i; 
for(i=1;i<4;i++) 
if(ag[i]!=ag[i-1])return(0); 
printf("OK%c\n",7); 
return(1); 
} 
index(int x,int y,int diskid) 
{ 
static int oldid=-1; 
int x1,y1; 
setwritemode(XOR_PUT); 
if(oldid!=-1) 
draw_disk_cross(x,y,oldid); 
draw_disk_cross(x,y,diskid); 
oldid=diskid; 
} 
draw_disk_cross(int x,int y,int diskid) 
{ 
int x1,y1,t,s; 
t=95;s=20; 
x1=x-5+(-diskid*20+t)*cos(3.14159/4*2/3); 
y1=y+(-diskid*20+t)*sin(3.14159/4*2/3); 
draw_cross(x1,y1); 
} 
draw_cross(int x,int y) 
{ 
line(x-5,y,x+5,y); 
line(x,y-5,x,y+5); 
} 
rotate_disk(int disk,int midx,int midy,int ag[4],int diskid,int direid) 
{ 
int i,r,color; 
switch(diskid){ 
case 0:r=100;color=7;   break; 
case 1:r=80;color=BLUE; break; 
case 2:r=60;color=RED;  break; 
case 3:r=40;color=GREEN;break; 
} 
for(i=0;(i<=45&&i>=0)||(i>=-5&&i<0);i+=direid) 
{ 
draw_a_disk(disk,midx,midy,r,color,ag[diskid]*45+i-direid,2,diskid); 
draw_a_disk(disk,midx,midy,r,color,ag[diskid]*45+i,0,diskid); 
} 
} 
int draw_a_disk(int disk[4][8],int x,int y,int r,int color,int angle1,int \ 
draw_bk,int diskid) 
{ 
int i; 
char tt[2]; 
float x1,y1; 
float angle; 
angle=angle1*3.14159/180; 
tt[1]='\0'; 
if(draw_bk==1){setfillstyle(1,color); 
fillellipse(x,y,r,r); 
} 
for(i=0;i<=7;i++) 
{ 
x1=x-5+(r-10)*cos(angle+i*3.14159/4); 
y1=y+(r-10)*sin(angle+i*3.14159/4); 
moveto(x1,y1); 
setcolor(color); 
tt[0]=-37; 
outtext(tt); 
if(draw_bk!=2) 
{ 
moveto(x1,y1); 
setcolor(WHITE); 
tt[0]=disk[diskid][i]+48; 
outtext(tt); 
} 
} 
}