#include <stdlib.h>  #include <graphics.h>  #include <math.h>  //-------------------------------------------Прототипы--------------------------------------------  void doska(int);  void zalivka(int,int,int);   void shash(int,int,int,int);  void shashka(int,int,int,int) ;   void krug ( int, int, int,int);  void krugoxod(int *, int *);  int xod1 (int *, int *);  int xod2 (int *, int *);  void krugoxoddamka(int *, int *);  void damkashashka(int , int , int, int);  int damkaxodleni(int *,int *, int *, int *,int);  int damkaxodlevv(int *,int *, int *, int *,int);  int damkaxodrivv(int *,int *,int *, int *,int);  int damkaxodrini(int *,int *,int *, int *,int);  int damkaxod(int *, int *);    int main()  {    initwindow(560,560);    doska(5);      zalivka(105,35,5);    zalivka(35,105,5);    zalivka(105,175,5);    zalivka(35,245,5);    zalivka(105,315,5);    zalivka(35,385,5);    zalivka(105,475,5);    zalivka(35,545,5);        shash(35,35,3,3);    shash(105,105,3,3);    shash(35,175,3,3);        shash(105,385,4,4);    shash(35,455,4,4);      shash(105,525,4,4);       int x=245,y=245,code;     int t;    x=35,y=35;         //-------------------------------------------------------------------------------------------------------------------    while(1)   {      do{  	 do{  	  	krugoxod(&x,&y);	   	      }	      while(getpixel(x,y+14)!=4);      if (getpixel(x,y)==6) t=damkaxod(&x,&y);      if(getpixel(x,y)==4) { t=xod1(&x,&y); if((y<70) )damkashashka(x,y,4,6);}   	 }      while(t==0);  	  	                  	   do{  		 do{krugoxod(&x,&y);} while(getpixel(x,y+14)!=3);  	             if (getpixel(x,y)==6) t=damkaxod(&x,&y);  		 if(getpixel(x,y)==3) { t=xod2(&x,&y); if((y>560-70)) damkashashka(x,y,3,6);}  	        }       while(t==0);         }           //-------------------------------------------------------------------------------------------------------------------   getch();               closegraph();        // закрываем графическое окно   return 0;  }  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     void doska(int n)      {        setcolor(n);         //цвет линий          int x1,y1,x,y;       for(x=0;x<=560;x+=70)      {        y=560; y1=0;        moveto(x,y1);        lineto(x,y);       }               for(y=0;y<=560;y+=70)      {        x=560; x1=0;        moveto(x1,y);        lineto(x,y);      }              }          //----------------------------------------------------       void zalivka(int x0,int y0, int n)     {              for(int x=0;x+x0<=560;x+=140)      {          setfillstyle ( 1, 1 );           floodfill(x0+x,y0,n);      }      }     //----------------------------------------------------      void shash(int x0,int y0,int n, int color)      {          setcolor(n);          for(int x=0;x+x0<=560; x+=140)          {  	        circle ( x0+x,y0, 25);    	        setfillstyle ( 1,  color ); // сплошная заливка, цвет color2  	        floodfill(x0+x,y0,n);  // заполняем цветом color2 до границы  color1          }      }   //----------------------------------------------------       void shashka(int x0,int y0,int n, int color)      {          setcolor(n);          circle ( x0,y0, 25);            setfillstyle ( 1,  color ); // сплошная заливка, цвет color2          floodfill(x0,y0,n);  // заполняем цветом color2 до границы  color1      }   //----------------------------------------------------  void krug ( int x, int y, int color1,int color2 )   {   setcolor(color1);       setfillstyle ( 1, color2 );        circle(x,y,10);        floodfill(x,y,color1);    }  //----------------------------------------------------  int xod1 (int *x, int *y)  {        int  k=4; int ret=0;        int   code=1; int flag=0;           while ( (code!=80)&& (flag!=1) )          {                code = getch();                switch ( code )                 {                   case 75: {                               if((getpixel(*x-70, *y-70+14)==0)&&((*x-70)>=0)&&((*y-70)>=0) && (flag==0))                                    {                                      shashka(*x-70,*y-70,k,k);                                       shashka(*x,*y,0,0);                                      *x=*x-70;                                      *y=*y-70;                                       flag=1;                                      ret=1;                                      break;                                   }                                  if ( (getpixel(*x-70, *y-70+14)==3) && (getpixel(*x-140, *y-140)==0) && ((*x-140)>=0) && ((*y-140)>=0) && (code!=80) )                                   {                                       shashka(*x-140,*y-140,k,k);                                       shashka(*x-70,*y-70,0,0);                                       shashka(*x,*y,0,0);                                       *x=*x-70*2;                                       *y=*y-70*2;                                       flag=1;                               if (((getpixel(*x-70, *y-70+14)==3) && (getpixel(*x-140, *y-140)==0)) || ( (getpixel(*x+70, *y-70+14)==3) && (getpixel(*x+140, *y-140)==0))) flag=2;                                       ret=1;  												 break;                                    }                                  }                  case 77: {                               if( (getpixel(*x+70, *y-70+14)==0) && ((*x+70)<=560) && ((*y-70)>=0) &&(flag==0) )                                   {                                     shashka(*x+70,*y-70,k,k);                                     shashka(*x,*y,0,0);                                     *x=*x+70;                                     *y=*y-70;                                     flag=1;                                     ret=1;                                     break;                                  }                                                                if( (getpixel(*x+70, *y-70+14)==3) && (getpixel(*x+140, *y-140)==0) && ((*x+140)<=560) && ((*y-140)>=0)&& (code!=80) )                                   {                                      shashka(*x+140,*y-140,k,k);                                     shashka(*x+70,*y-70,0,0);                                     shashka(*x,*y,0,0);                                     *x=*x+140;                                     *y=*y-140;                                     flag=1;                              if (((getpixel(*x-70, *y-70+14)==3) && (getpixel(*x-140, *y-140)==0)) || ( (getpixel(*x+70, *y-70+14)==3) && (getpixel(*x+140, *y-140)==0))) flag=2;                                     ret=1;  											  break;                                                                       }                              }                }                if (flag==1) break;          }   return ret;          }   //----------------------------------------------------  int xod2 (int *x, int *y)  {      int  k=3;int flag=0;int ret=0;      int  code=1;          while ( (code!=80)&&(flag!=1) )          {                code = getch(); // ждем нажатия клавиши                switch ( code )                 {                   case 75:{                              if ( (getpixel(*x-70, *y+70+14)==0) && ((*x-70)>=0) && ((*y+70)<=560)&&(flag==0) )                                 {                                   shashka(*x-70,*y+70,k,k);                                    shashka(*x,*y,0,0);                                    *x=*x-70;                                   *y=*y+70;                                   flag=1;                                   ret=1;                                   break;                                }                              if ( (getpixel(*x-70, *y+70+14)==4) && (getpixel(*x-140, *y+140)==0) && ((*x-140)>=0) && ((*y+140)<=560) && (code!=80) )                                 {                                    shashka(*x-140,*y+140,k,k);                                   shashka(*x-70,*y+70,0,0);                                   shashka(*x,*y,0,0);                                   *x=*x-70*2;                                   *y=*y+70*2;                                   flag=1;                             if ( (getpixel(*x-70, *y+70+14)==4) && (getpixel(*x-140, *y+140)==0)|| (getpixel(*x+70, *y+70+14)==4) && (getpixel(*x+140, *y+140)==0)) flag=2;                                   ret=1;  											break;                                }                              }                                                                                case 77:{                              if ( (getpixel(*x+70, *y+70+14)==0) && ((*x+70)<=560) && ((*y+70)<=560)&&(flag==0) )                                 {                                   shashka(*x+70,*y+70,k,k);                                    shashka(*x,*y,0,0);                                   *x=*x+70;                                   *y=*y+70;                                    flag=1;                                   ret=1;  											break;                                }                             if ( (getpixel(*x+70, *y+70+14)==4) && (getpixel(*x+140, *y+140)==0) && ((*x+140)<=560) && ((*y+140)<=560) &&(code!=80) )                                 {                                    shashka(*x+140,*y+140,k,k);                                   shashka(*x+70,*y+70,0,0);                                   shashka(*x,*y,0,0);                                   *x=*x+70*2;                                   *y=*y+70*2;                                   flag=1;                                   if ( (getpixel(*x-70, *y+70+14)==4) && (getpixel(*x-140, *y+140)==0)|| (getpixel(*x+70, *y+70+14)==4) && (getpixel(*x+140, *y+140)==0)) flag=2;                                   ret=1;  											break;                                }                            }                                                                              }             if(flag==1) break;             }    return ret;      }       //----------------------------------------------------  void krugoxoddamka(int *x, int *y)  {       int code=0;        while ( code!=27 ) // бесконечный цикл          {   krug ( *x, *y, 6,6 ); // рисуем                code = getch(); // ждем нажатия клавиши               krug ( *x, *y, getpixel(*x, *y+11),getpixel(*x, *y+11) ); // стираем квадрат             switch ( code )             { // выбор направления              case 75: if(*x>35) *x-=70; break; // влево              case 77: if(*x<560-35) *x +=70; break; // вправо              case 72: if(*y>35) *y -=70; break; // вверх              case 80: if(*y<560-35) *y+=70; // вниз            }  			          }   }  //----------------------------------------------------  void krugoxod(int *x, int *y){       int code=0;        while ( code!=27 )          {            krug ( *x, *y, 2,2 );             code = getch();             krug ( *x, *y, getpixel(*x, *y+11),getpixel(*x, *y+11) );             switch ( code )             {               case 75: if(*x>35) *x-=70; break; // влево              case 77: if(*x<560-35) *x +=70; break; // вправо              case 72: if(*y>35) *y -=70; break; // вверх              case 80: if(*y<560-35) *y+=70; // вниз            }          }   }    //----------------------------------------------------  void damkashashka(int x, int y, int k,int colorcircl)  {              shashka(x,y,k,k) ;       setcolor(colorcircl);        setfillstyle ( 1, colorcircl); // сплошная заливка, цвет color2       circle(x,y,13); // рисуем окружность радиусом 20 цвет color1       floodfill(x,y,colorcircl);  // заполняем цветом color2 до границы  color1  }  //----------------------------------------------------   int damkaxodleni(int *x0,int *y0, int *x, int *y,int k)    {     	 int l;  	 if (k==4) l=k-1;  	 if (k==3) l=k+1;   	 if ((*x<*x0)&& (*y<*y0)&&(getpixel(*x,*y)==0)&& (abs((*x-*x0)/70)==abs((*y-*y0)/70)))                 {                 int     i=*x0-70;              int     j=*y0-70;               int     s4et=0;                       while((i>*x)&&(j>*y) )                   {                      if (getpixel(i,j)!=0) s4et++;                                   i-=70;                             j-=70;                                     }              	  if (s4et==0) {damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); return 1;                }                   if (s4et==1)                   {                           i=*x0-70;                       j=*y0-70;                       while((i>*x)&&(j>*y))                       {                   if (getpixel(i,j)==k)                      {                               return 0; break;                                          }                     if (getpixel(i,j+14)==l)                          {                              damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0);   									 shashka(i,j,0,0); return 1; break;                          }                          i-=70;                          j-=70;                                         }                   }                }	   }  //----------------------------------------------------  int damkaxodlevv(int *x0,int *y0, int *x, int *y,int k)  {   int l;  	 if (k==4) l=k-1;  	 if (k==3) l=k+1;   	 if ((*x<*x0)&& (*y>*y0)&&(getpixel(*x,*y)==0)&& (abs((*x-*x0)/70)==abs((*y-*y0)/70)))               {                   int   i=*x0-70;                int   j=*y0+70;                 int s4et=0;                   while((i>*x)&&(j<*y))                   {                      if (getpixel(i,j)!=0)                      {                           s4et++;                                  }                         i-=70;                      j+=70;                                     }                   if (s4et==0) {damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); return 1;}                   if (s4et==1)                   {                           i=*x0-70;                       j=*y0+70;                       while((i>*x)&&(j<*y))                       {                   if (getpixel(i,j)==k)                          {                               return 0; break;                                          }                      if (getpixel(i,j+14)==l)                          {                              damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); shashka(i,j,0,0); return                                                                                                                                                                                                                                                                                                                                                                                                            1; break;                          }                          i-=70;                          j+=70;                                         }                   }                }  }  //----------------------------------------------------  int damkaxodrivv(int *x0,int *y0,int *x, int *y,int k)   {  int l;  	 if (k==4) l=k-1;  	 if (k==3) l=k+1;     if ((*x>*x0)&& (*y>*y0)&&(getpixel(*x,*y)==0)  && (abs((*x-*x0)/70)==abs((*y-*y0)/70)) )               {                    int  i=*x0+70;                 int  j=*y0+70;  					int s4et=0;                    while((i<*x)&&(j<*y))                   {                      if (getpixel(i,j)!=0)                     {                           s4et++;                                }                         i+=70;                      j+=70;                                      }              	  if (s4et==0) {damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); return 1;}                   if (s4et==1)                   {                           i=*x0+70;                       j=*y0+70;                       while((i<*x)&&(j<*y))                       {                          if (getpixel(i,j)==k)                          {                               return 0; break;                                          }                             if (getpixel(i,j+14)==l)                          {                              damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); shashka(i,j,0,0); return 1; break;                          }                          i+=70;                          j+=70;                                         }                   }                }  	   }  //----------------------------------------------------  int damkaxodrini(int *x0,int *y0,int *x, int *y,int k)  {   int l;  	 if (k==4) l=k-1;  	 if (k==3) l=k+1;   	 if ((*x>*x0)&& (*y<*y0)&&(getpixel(*x,*y)==0) && (abs((*x-*x0)/70)==abs((*y-*y0)/70)))               {                   int   i=*x0+70;                int   j=*y0-70;  				  int s4et=0;                    while((i<*x)&&(j>*y))                   {                      if (getpixel(i,j)!=0)                      {                           s4et++;                                   }                         i+=70;                      j-=70;                                     }              	  if (s4et==0) {damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); return 1;}                   if (s4et==1)                   {                           i=*x0+70;                       j=*y0-70;                       while((i<*x)&&(j>*y))                       {                          if (getpixel(i,j)==k)                          {                               return 0; break;                                          }                             if (getpixel(i,j+14)==l)                          {                              damkashashka(*x,*y,k,6); damkashashka(*x0,*y0,0,0); shashka(i,j,0,0); return 1; break;                          }                          i+=70;                          j-=70;                                         }                   }                } 	   }  //----------------------------------------------------   int damkaxod(int *x, int *y)  {     int code; int flag=0,ret=0;     int x0=*x,y0=*y,i=0,j=0,s4et=0;      if((getpixel(x0,y0)==6)&&(getpixel(x0,y0+14)==3))     {    		  	krugoxoddamka(x,y);	      if ((*x<x0)&& (*y<y0)&&(getpixel(*x,*y))==0)  ret=damkaxodleni(&x0,&y0,x,y,3);     if ((*x<x0)&& (*y>y0)&&(getpixel(*x,*y)==0))  ret=damkaxodlevv(&x0,&y0,x,y,3);     if ((*x>x0)&& (*y>y0)&&(getpixel(*x,*y)==0))  ret=damkaxodrivv(&x0,&y0,x,y,3);     if ((*x>x0)&& (*y<y0)&&(getpixel(*x,*y)==0))  ret=damkaxodrini(&x0,&y0,x,y,3);     }  	     if((getpixel(x0,y0)==6)&&(getpixel(x0,y0+14)==4))     {                 krugoxoddamka(x,y);	            		   if ((*x<x0)&& (*y<y0)&&(getpixel(*x,*y))==0)	ret=damkaxodleni(&x0,&y0,x,y,4);           if ((*x<x0)&& (*y>y0)&&(getpixel(*x,*y)==0))  ret=damkaxodlevv(&x0,&y0,x,y,4);  		   if ((*x>x0)&& (*y>y0)&&(getpixel(*x,*y)==0))  ret=damkaxodrivv(&x0,&y0,x,y,4);  		   if ((*x>x0)&& (*y<y0)&&(getpixel(*x,*y)==0))  ret=damkaxodrini(&x0,&y0,x,y,4);     }       	return ret;          }