Từ 1 tới 2 trên tổng số 2 kết quả

Đề tài: Giải thích hộ mình hàm này cái

  1. #1
    Ngày gia nhập
    04 2007
    Bài viết
    15

    Mặc định Giải thích hộ mình hàm này cái

    Giải thích hộ tớ đoạn code hàm iNit().đây là trò line


    Code:
    #include<dos.h>
    #include<stdio.h>
    #include<conio.h>
    #include<time.h>
    #include<math.h>
    #include<stdlib.h>
    #include<string.h>
    #include<graphics.h>
    
    #define true 1
    #define folse 0
    #define TOP 110
    #define __mouse_c
    #define Speed 50
    #define  LEFT 140
    typedef  int arr[4];
    typedef  char arrstr[3][15];
    typedef  int theway[99];
    typedef  int arrint[25][25];
    typedef  int group[89];
    
    /***************************NGUYEN MAU CAC HAM*****************************/
    void load();
    void New();
    void Back();
    void Save();
    void about();
    void cancle();
    void process();
    void contain();
    void framePro();
    void initmouse();
    void mouseshow();
    void mousehide();
    void iNitGraphic();
    
    /*------------------------------------------------------------------------*/
    
    void he(int key);
    void ga(int key);
    void fi( int key);
    void iNit();
    void score(int x,int c);
    
    void wait(int i,int j,int c);
    void saveFile(char filename[10]);
    void loadFile();
    void text(int x,int y,char s[10]);
    void dinhke(int x,int y);
    void drawBall1(arr vtx,arr vty,arr vtc);
    void frame(int x,int y,int r,int c,int m);
    void drawBall(int x,int y,int h,int t,int c);
    void ballShow(int i,int j,int color,int flag);
    void menu(int x,int y,int n,arrstr s,char key);
    void Tlink(int x,int y,int m1,int m2,int k,int cho);
    void butTon(int x,int y,int r,int c,int k,int mt,int md,int mn);
    void strdel(char s[10],int pos,int count  );
    
    /*------------------------------------------------------------------------*/
    
    int mark(int i,int j);
    void mousemove(int *x,int *y);
    int randd(arr i,arr j,arr c);
    int mouselclick(int *x,int*y);
    void mousepos(int*x,int*y);
    int duong_di(int i1,int j1,int i2,int j2);
    int dan_nhan(int dinh_dix,int dinh_diy,int dinh_denx,int dinh_deny);
    group ke;
    
    char *readString(char s[20]);
    char *getString(int x,int y,int m1,int m2,int d);
    
    /*------------------------BIEN TOAN CUC-----------------------------*/
    FILE *f;
    int top;
    int mar2,mar3;
    int flagEnd,co;
    int ii,jj,ii1,jj1;
    arrstr fil,hel,gam;
    arrint ball,ball1,dinh;
    arr vtx,vty,vtc,vtx1,vty1,vtc1,a,b;
    
    /***************************MAIN******************************************/
    void main()
    { char x[10];
         clrscr();
         iNitGraphic();
         initmouse();
    	 a[0]=-1;b[0]=0;
    	 a[1]=0 ;b[1]=1;
    	 a[2]=1 ;b[2]=0;
    	 a[3]=0 ;b[3]=-1;
         co=0;
         setbkcolor(3);
         iNit();
    	 framePro();
    	 strcpy(fil[0],"Save Ctrl+S");
    	 strcpy(fil[1],"Load  Ctrl+L");
    	 strcpy(fil[2],"Exit  Ctrl+E");
    	 strcpy(gam[0],"New   Ctrl+N");
    	 strcpy(gam[1],"Back  Ctrl+B");
    	 strcpy(hel[0],"Contain");
    	 strcpy(hel[1],"About");
    	 process();
    	 getch();
    	 closegraph();
    
    }
    
    /****************************************************************************
    *
    *                          FUNCTIONS
    *
    ****************************************************************************/
    
    void initmouse()//K
     {
       _AX=0x00;
       geninterrupt(0x33);
     }
    /*__________________________________________________________________________*/
    void mouseshow()//h
     {
       _AX=0x01;
       geninterrupt(0x33);
     }
    /*__________________________________________________________________________*/
    void mousehide()//an
     {
       _AX=0x02;
       geninterrupt(0x33);
     }
    /*__________________________________________________________________________*/
    void mousemove(int *x,int *y)//di
     {
        _AX=0x04;
        geninterrupt(0x33);
        _CX=*x;  _DX=*y;
     }
    /*__________________________________________________________________________*/
    int mouselclick(int *x,int *y) //nh
      {
         _AX=0x05;
         geninterrupt(0x33);
         *x=_CX;   *y=_DX;
         return _BX;
      }
    /*__________________________________________________________________________*/
    void mousepos(int*x,int*y)//vi
     {
      _AX=0x03;
       geninterrupt(0x33);
       *x=_CX;  *y=_DX;
     }
     //____________________________________________________________
    void iNitGraphic()
     {
       int mh=0,mode=0,errorcode;
    	initgraph(&mh,&mode,"C:\\BorlandC\\BGI");
       errorcode=graphresult();
       if(errorcode!=grOk)
        {
          printf("Loi do hoa\n");
          getch();
          exit(1);
        }
    }
    /*__________________________________________________________________________*/
    void frame(int x,int y,int r,int c,int m)
    {
      setfillstyle(1,m);
      bar(x,y,x+r,y+c);
      setcolor(8);
      rectangle(x+1,y+1,x+r-2,y+c-2);
      setcolor(15);
      rectangle(x+2,y+2,x+r-1,y+c-1);
    }
    /*__________________________________________________________________________*/
    void  text(int x,int y,char s[10])
     {
       setcolor(8);
       outtextxy(x,y,s);
       setcolor(15);
       outtextxy(x+1,y+1,s);
     }
    /*______________________________________________________________________*/
    void butTon(int x,int y,int r,int c,int k,int mt,int md,int mn)
     {
       int i;
       setfillstyle(1,mn);
       bar(x+k,y+k,x+r-k,y+c-k);
       setcolor(mt);
       for(i=0;i<=(k-1);++i)
         {
           line(x+i,y+i,x+r-i,y+i);
           line(x+i,y+i,x+i,y+c-i);
         }
       setcolor(md);
       for(i=0;i<=(k-1);++i)
         {
    	line(x+r-i,y+i,x+r-i,y+c-i);
    	line(x+i,y+c-i,x+r-i,y+c-i);
         }
    }
    /*__________________________________________________________________________*/
    void drawBall(int x,int y,int h,int t,int c)
     {
        mousehide();
        setcolor(8);
        setfillstyle(1,8);
        fillellipse(x+h/4,y+t,h/2+2,t/4);
        setcolor(c);
        setfillstyle(1,c);
        fillellipse(x,y,h,t);
        setfillstyle(1,c+8);
        fillellipse(x,y,h/3+1,t/3+1);
        fillellipse(x+h/2,y-h/2,h/4,t/4);
        putpixel(x,y,c);
        mouseshow();
     }
    /*________________________________________________________________________*/
    void clearball(int i,int j)
     {
       setcolor(7);
       setfillstyle(1,7);
       bar(LEFT+40*i+2,TOP+40*j+2,LEFT+40*i+38,TOP+40*j+38);
     }
    /*__________________________________________________________________________*/
    void ballShow(int i,int j,int color,int flag)
         {
    	if(flag==1)  drawBall(LEFT+40*i+20,TOP+40*j+20,13,13,color);
    	else drawBall(LEFT+40*i+20,TOP+40*j+20,4,4,color);
         }
    /*__________________________________________________________________________*/
    void drawBall1(arr vtx,arr vty,arr vtc)
        {
           int h,t;
    
    	 mousehide();
    	 h=4;
    	 while(h<13)
    	  {
    	    delay(5);h+=1;
    	    for(t=0;t<=2;++t)
    	      if(ball[vtx[t]+8][vty[t]+8]<0 )
    	       {
    		delay(5);
    		drawBall(LEFT+40*vtx[t]+20,TOP+40*vty[t]+20,h,h,-vtc[t]);
    	       }
    	  }
    	for(t=0;t<=2;++t)
    	if(ball[vtx[t]+8][vty[t]+8]<0 ) ball[vtx[t]+8][vty[t]+8]=-ball[vtx[t]+8][vty[t]+8];
           mouseshow();
         }
    /*__________________________________________________________________________*/
    void wait(int i,int j,int c)
        {
         int x,y;
    	x=LEFT+i*40;
    	y=TOP+j*40;
    	setfillstyle(1,10);
    	bar(x+2,y+2,x+38,y+38);
    	ballShow(i,j,c,1);
         }
    /*__________________________________________________________________________*/
    void cancle()
        {
         char s[10];
         int x,y;
           itoa(mar2,s,50);
           frame(LEFT+60,TOP+20,240,110,9);
           text(LEFT+110,TOP+50,"Game is finished !");
           text(LEFT+110,TOP+70,strcat("Your Scores is:",s));
           butTon(LEFT+170,TOP+90,20,20,1,15,1,9);
           setcolor(15);
           outtextxy(LEFT+173,TOP+97,"Ok");
           mouselclick(&x,&y);
    
    	  do
    	   {
    		mouseshow();
    		mouselclick(&x,&y);
    	   }
    	   while ((_BX==1)&&(x>LEFT+170)&&(x<LEFT+190)&&(y>TOP+90)&&
    	      (y<TOP+110)||!(kbhit()));
    
           mousehide();
           butTon(LEFT+170,TOP+90,20,20,1,1,15,9);
           outtextxy(LEFT+173,TOP+97,"Ok");
           delay(100);
           exit(1);
         }
    /*-------------------------------------------------------------------*/
    int randd(arr i,arr j,arr c)
       {
         int t,n,h;
    	mousehide();
    	n=0;
    	for(h=0;h<=8;++h)
    	for(t=0;t<=8;++t)
    	if(ball[h+8][t+8]>0 ) n++;
    	if (n>=78 ) cancle();
    	randomize();
    	for( t=0;t<=2;t++)
    	{
    	  do
    	  {
    	    i[t]=random(9);
    	    j[t]=random(9);
    	  }
    	  while (ball[i[t]+8][j[t]+8]!=0);
    		c[t]=1+random(6);
    	  ball[i[t]+8][j[t]+8]=-c[t];
    	  ballShow(i[t],j[t],c[t],0);
    	  drawBall(LEFT+t*35+145,TOP-65,10,10,c[t]);
    	}
        mouseshow();
        return 0;
    }
    
    /*__________________________________________________________________________*/
    void iNit()
        {
           int i,j;
    	   randomize();
    
    	   for(i=0;i<=24;++i)
    	   for(j=0;j<=7;++j)
    	  ball[i][j]=8;
    
    	   for(i=0;i<=24;++i)
    	   for (j=16;j<=24;++j)
    	  ball[i][j]=8;
    
    	   for(i=0;i<=7;++i)
    	   for(j=8;j<=16;++j)
    	  ball[i][j]=8;
    
    	   for (i=16;i<=24;++i)
    	   for (j=8;j<=16;++j)
    	  ball[i][j]=8;
    
    	   for(i=8 ;i<=16;++i)
    	   for(j=8;j<=16;++j)
    	  ball[i][j]=0;
    	  flagEnd=randd(vtx,vty,vtc);
    
    	   for (i=0;i<=2;i++)
    	  ball[vtx[i]+8][vty[i]+8]=-ball[vtx[i]+8][vty[i]+8];
    	  flagEnd=randd(vtx,vty,vtc);
    
    	   for (i=0;i<=2;i++)
    	  ball[vtx[i]+8][vty[i]+8]=-ball[vtx[i]+8][vty[i]+8];
    	  flagEnd=randd(vtx,vty,vtc);
    	   mar2=0;
     }
    /*__________________________________________________________________________*/
    void score(int x,int c)
    {
         char *s;
    	s=(char*)calloc(20,sizeof(char));
    	itoa(x,s,10);
    	setcolor(c);
    	settextstyle(0,0,2);
    	settextjustify(RIGHT_TEXT,RIGHT_TEXT);
    	outtextxy(LEFT+355,TOP-30,s);
    	settextstyle(0,0,1);
    	settextjustify(LEFT_TEXT,RIGHT_TEXT);
    	free(s);
     }
    /*__________________________________________________________________________*/
    void framePro()
     {
        int i,j;
    	setfillstyle(6,8);//chon mau to mau
    	 bar(LEFT+5,TOP-75,LEFT+368,TOP+367);
    	 butTon(LEFT-2,TOP-81,363,442,1,15,8,7);
    	 butTon(LEFT,TOP-79,359,30,1,15,8,7);
    	 butTon(LEFT,TOP-48,359,45,1,15,8,9);
    	 for(i=0;i<=8;++i)
    	 for(j=0;j<=8;++j)
    	   {
    	     butTon(LEFT+i*40,TOP+j*40,39,39,1,15,8,7);
    	     if(ball[i+8][j+8]>0)  ballShow(i,j,ball[i+8][j+8],1);
    	     else if(ball[i+8][j+8]<0)  ballShow(i,j,-ball[i+8][j+8],0);
    	   }
    	 setcolor(2);
    	 settextstyle(0,0,4);
    	 outtextxy(LEFT+122,TOP-38,"LINE");
    	 setcolor(10);
    	 outtextxy(LEFT+120,TOP-40,"LINE");
    	 frame(LEFT+258,TOP-75,100,25,7);
    	 frame(5,40,120,80,7);
    	 settextstyle(0,0,1);
    	 outtextxy(15,50,"NG-Xuan Truong");
    	 setcolor(4);
    	 outtextxy(15,50,"NG-Xuan Truong");
    	 outtextxy(20,70,"LOP Tin4a ");
    	 outtextxy(20,90,"CNTT");
    	 settextstyle(0,0,2);
    	 text(LEFT+261,TOP-70,"Scores");
    	 score(mar2,12);
    	 frame(LEFT+1,TOP-75,40,17,7);
    	 settextstyle(0,0,1);
    	 text(LEFT+6,TOP-70,"File");
    	 frame(LEFT+42,TOP-75,40,17,7);
    	 text(LEFT+47,TOP-70,"Game");
    	 frame(LEFT+84,TOP-75,40,17,7);
    	 text(LEFT+89,TOP-70,"Help");
    	 for(i=0;i<=2;++i)
    	    {
    	       drawBall(LEFT+i*35+145,TOP-65,10,10,vtc[i]);
    	    }
         }
    
    /*__________________________________________________________________________*/
    int mark(int i,int j)
     {
        arr m;
        char k[7];
        int mar,t,h;
        delay(100);
        mar=0;
           for(t=0;t<=8;++t) k[t]=0;
           for(t=0;t<=3;++t) m[t]=0;
    	while(ball[i+k[0]+1+8][j+8]==ball[i+8][j+8])    k[0]+=1;
    	while(ball[i+k[1]+1+8][j+k[1]+1+8]==ball[i+8][j+8])  k[1]+=1;
    	while(ball[i+8][j+k[2]+1+8]==ball[i+8][j+8])   k[2]+=1;
    	while(ball[i-k[3]+7][j+k[3]+9]==ball[i+8][j+8])    k[3]+=1;
    	while(ball[i-k[4]+7][j+8]==ball[i+8][j+8])  k[4]+=1;
    	while(ball[i-k[5]+7][j-k[5]+7]==ball[i+8][j+8])   k[5]+=1;
    	while(ball[i+8][j-k[6]+7]==ball[i+8][j+8])   k[6]+=1;
    	while(ball[i+k[7]+9][j-k[7]+7]==ball[i+8][j+8])    k[7]+=1;
    	for(t=0;t<=3;++t)
    	  {
    	    switch(k[t]+k[t+4]+1)
    	     {
    	       case 5: {m[t]=5;}break;
    	       case 6: {m[t]=12;}break;
    	       case 7: {m[t]=21;}break;
    	       case 8: {m[t]=32;}break;
    	       case 9: {m[t]=45;}break;
    	     }
    	    mar=mar+m[t];
    	  }
    	if ((k[0]+k[4])>=4)
    	for(h=-k[4];h<=k[0];++h)
    	   {
    	      ball[i+h+8][j+8]=0;
    	      clearball(i+h,j);
    	   }
    	if ((k[1]+k[5])>=4)
    	for(h=-k[5];h<=k[1];++h)
    	  {
    	    ball[i+h+8][j+h+8]=0;
    	    clearball(i+h,j+h);
    	  }
    	if ((k[2]+k[6])>=4)
    	for(h=-k[6];h<=k[2];++h)
    	  {
    	    ball[i+8][j+h+8]=0;
    	    clearball(i,j+h);
    	  }
    	if((k[3]+k[7])>=4)
    	for(h=-k[7];h<=k[3];++h)
    	  {
    	     ball[i-h+8][j+h+8]=0;
    	     clearball(i-h,j+h);
    	  }
    	return mar;
     }
    /*__________________________________________________________________________*/
    void Tlink(int x,int y,int m1,int m2,int k,int cho)
    {
       mousehide();
       setcolor(m1);
       outtextxy(x,y,"_");
       outtextxy(x,y+1,"_");
       if(kbhit())
         {
           setcolor(m2);
           outtextxy(x,y,"_");
           outtextxy(x,y+1,"_");
           return;
         }
       delay(k*cho);
       setcolor(m2);
       outtextxy(x,y,"_");
       outtextxy(x,y+1,"_");
       if(kbhit()) return ;
       delay(cho);
    }
    void strdel(char *s,int pos,int num)
     {
       int i,n;
        n=strlen(s)-num-pos+1;
        for(i=0;i<n;i++)
        s[i+pos]=s[i+pos+num];
    }
    char *getString(int x,int y,int m1,int m2,int d)
      {
         int xx,i;
         char s[20];
         char c;
         int flag,h;
          xx=x;i=1;
          strcpy(s," "); flag=1;
          while(flag)
    	{
    	  Tlink(x+8,y,m1,m2,2,100);
    	  if(kbhit())
    	    {
    	      c=getch();
    	      if((c==13)||(c==27))  flag=0;
    	      else if (((c==75)||(c==8))&&(strlen(s)>0))
    		{
    		    setcolor(m2);outtextxy(xx,y,s);
    		    setcolor(m1);
    		    strdel(s,strlen(s)-1,1);
    		    x=x-8;
    		    setcolor(m1); outtextxy(xx,y,s);
    		 }
    	       else if((c>=32)&&(c<=125)&&(strlen(s)<=d))
    		 {
    		    h=strlen(s);
    		    s[h]=c;h++;
    		    s[h]='\0';
    		    i++; x=x+8;
    		    setcolor(m1);
    		    outtextxy(xx,y,s);
    		 }
    	    }
         }
        return s;
     }
    
    /*__________________________________________________________________________*/
    char *readString(char s[20])
        {
         char *str;
         int  c;
         int i,j;
         str = (char *) calloc(50,sizeof(char));
    	butTon(160,220,320,50,1,15,8,9);
    	butTon(210,240,260,20,1,8,15,15);
    	butTon(410,223,60,14,1,8,15,15);
    	text(170,223,s);
    	setcolor(14);
    	outtextxy(170,245,"File");
    	setcolor(8);
    	outtextxy(415,228,"*.lin");
    	strcpy(str,getString(220,245,8,15,30));
    	i=strlen(str);j=0;
    	while(i>=1)
    	 {
    	    if(str[i]=='.') { i=1;j+=1;}
    	    else
    	     j+=1;i--;
    	 }
    	if(j>=strlen(str))
    	{
    	   strcat(str,".lin");
    	   strcpy(s,str);
    	   return s;
    	}
    	strcpy(s,str);
    	strdel(str,strlen(s)-j+1,j);
    	strcat(str,".lin");
    	strcpy(s,str);  free(str);
    	return s;
         }
    void saveFile(char filename[20])
        {
          int i,j;
          if(strcmpi(filename,".lin")==0 ) return ;
          f=fopen("filename","wb");
    	fwrite(&mar2,sizeof(mar2),1,f);
          for(i=0;i<=2;++i)
    	fwrite(&vtx[i],sizeof(vtx[i]),3,f);
          for(i=0;i<=2;++i)
           fwrite(&vty[i],sizeof(vty[i]),3,f);
          for(i=0;i<=2;++i)
    	fwrite(&vtc[i],sizeof(vtc[i]),3,f);
          for (i=0;i<=8;++i)
          for (j=0;j<=8;++j)
    	fwrite(&ball[i+8][j+8],sizeof(ball[i+8][j+8]),89,f);
    	fclose(f);
        }
    /*__________________________________________________________________________*/
    void Save()
     {
        char *P;char s[20];
        unsigned size;
        size=imagesize(160,220,480,270);
        P=(char*)malloc(size);
        getimage(160,220,480,270,P);
        strcpy(s,readString("Save file"));
        saveFile(s);
        putimage(160,220,P,COPY_PUT);free(P);
        return;
     }
    /*__________________________________________________________________________*/
    void loadFile()
    {
      int i,j;
       f=fopen("filename","rb");
       if(f==NULL)
        {
          getch();
          return ;
        }
         fread(&mar2,sizeof(mar2),1,f);
       for(i=0;i<=2;i++)
         fread(&vtx[i],sizeof(int),3,f);
       for(i=0;i<=2;i++)
         fread(&vty[i],sizeof(int),3,f);
       for(i=0;i<=2;i++)
         fread(&vtc[i],sizeof(int),3,f);
       for(i=0;i<=8;i++)
       for(j=0;j<=8;j++)
         fread(&ball[i+8][j+8],sizeof(ball[i+8][j+8]),89,f);
         fclose(f);
     }
    /*__________________________________________________________________________*/
    void load()
    {
        char s[20];
        char size;
        strcpy(s,readString("Load file"));
        loadFile(s);
        framePro();
        return;
     }
    /*__________________________________________________________________________*/
    void New()
     {
        iNit();
        framePro();
     }
    /*__________________________________________________________________________*/
    void Back()
     {
       int h,t;
       if ((ii==ii1)&&(jj==jj1)) return  ;
       ii=ii1;jj=jj1;
       for (t=0;t<=2;++t)
        {
          vtx[t]=vtx1[t];
          vty[t]=vty1[t];
        }
       for (h=0;h<=8;++h)
       for (t=0;t<=8;++t)
         {
    	clearball(h,t);
    	ball[h+8][t+8]=ball1[h+8][t+8];
    	if(ball[h+8][t+8]>0)  ballShow(h,t,ball[h+8][t+8],1);
    	else if (ball[h+8][t+8]<0)  ballShow(h,t,-ball[h+8][t+8],0);
         }
       score(mar2,9);
       mar2=mar3;
       score(mar2,12);
     }
    /*__________________________________________________________________________*/
    void contain()
     {
        return  ;
     }
    /*__________________________________________________________________________*/
    void about()
     {
       return  ;
     }
    /*__________________________________________________________________________*/
    void fi( int key)
    {
      if (key==1)  Save();
      else if(key==2)  load();
      else cancle();
    }
    /*__________________________________________________________________________*/
    void ga(int key)
    {
      if (key==1)
        {
          mousehide();
          New();
          mouseshow();
        }
      else Back();
     }
    /*__________________________________________________________________________*/
    void he(int key)
    {
      if (key==1)  contain();
      else about();
    }
    /*__________________________________________________________________________*/
    void menu(int x,int y,int n,arrstr s,char key)
    {
       int flag;
       int a,b,i;
       unsigned size;
       char *P;
        size=imagesize(x,y,x+120,y+n*20);
        P=(char*)malloc(size);
         mousehide();
         getimage(x,y,x+120,y+n*20,P);
         flag=0;
         butTon(x,y,120,n*20,1,15,8,7);
         setcolor(8);
         settextstyle(0,0,1);
         for (i=1;i<=n-1;++i)
          {
    	 outtextxy(x+5,y+5+i*20,s[i]);
          }
         setfillstyle(1,1);
         bar(x+2,y+2,x+118,y+18);
         setcolor(14);
         outtextxy(x+5,y+5,s[0]);
         mouseshow();
           do
    	 {
    	   mousepos(&a,&b);
    	   if ((a<x)||(a>x+120)||(b<y-20)||(b>y+n*20))  flag=125;
    	   else if ((a>x+40)&&(b<y))  flag=125;
    	   else
    	     {
    	       for (i=0;i<=n-1;++i)
    	       if((a>=x)&&(a<=x+120)&&(b>=y+i*20+2)&&(b<=y+(i+1)*20-2))
    		   {
    		     if(i!=flag)
    		       {
    			 mousehide();
    			 mouselclick(&a,&b);
    			 setfillstyle(1,7);
    			 bar(x+2,y+flag*20+2,x+118,y+(flag+1)*20-2);
    			 setcolor(8);
    			 outtextxy(x+5,y+5+flag*20,s[flag]);
    			 setfillstyle(1,1);
    			 bar(x+2,y+i*20+2,x+118,y+(i+1)*20-2);
    			 setcolor(14);
    			 outtextxy(x+5,y+5+i*20,s[i]);
    			 flag=i;
    			 mouseshow();
    		       }
    		   }
    		 mouselclick(&a,&b);
    		 for(i=0;i<=(n-1);++i)
    		 if((a>=x)&&(a<=x+120)&&(b>=y+i*20)&&(b<=y+(i+1)*20))
    		   {
    		     if(key==1) fi(i+1);
    		     else if(key==2)   ga(i+1);
    		     else if(key==3)  he(i+1);
    		     flag=125;
    		   }
    	     }
    	  }
    	 while (flag!=125);mousehide();
    	 putimage(x,y,P,0 );
    	 free(P);
     }
    /*__________________________________________________________________________*/
    void dinhke(int x,int y)
    {
      int k,i,j;
      k=0;
      do
       {
         i=x+a[k];j=y+b[k];
         if ((dinh[i][j]>dinh[x][y]+1)&&(ball[i+8][j+8]<=0)&&
    	(i>=0)&&(j>=0)&&(j<=8)&&(i<=8))
    	{
    	 ke[i*10+j]=1;
    	 dinh[i][j]=dinh[x][y]+1;
           }
          k+=1;
        }
      while(k<=3);
    }
     /*__________________________________________________________________________*/
    int dan_nhan(int dinh_dix,int dinh_diy,int dinh_denx,int dinh_deny)
    {
      group  t_dinh,t_dinh1;
      int  i,j,cobao1,t;
      for (i=0;i<89;i++)
      {   ke[i]=0;
          t_dinh[i]=0;
      }
      ke[dinh_dix*10+dinh_diy]=1;
      t_dinh[dinh_dix*10+dinh_diy]=1;
      for(i=0;i<=8;++i)
      for(j=0;j<=8;++j)
      dinh[i][j]=125;
      dinh[dinh_dix][dinh_diy]=0;
      do
       { cobao1=0;
         for (i=0;i<89;i++)
    	t_dinh1[i]=ke[i];
         for (i=0;i<=8;++i)
         for (j=0;j<=8;++j)
          {
    	if(t_dinh[i*10+j]!=0)  dinhke(i,j);
          }
         for(i=0;i<89;i++)
         {
           if ((t_dinh1[i]==0)&&(ke[i]==1)) t_dinh[i]=1;
           else t_dinh[i]=0;
         }
         if(t_dinh[dinh_denx*10+dinh_deny]) return 1;
         for(i=0;i<89;i++) if (t_dinh[i]!=0) cobao1=1;
       }
      while (cobao1);
      return 0;
    }
       /*-------------------------------------------------------*/
    int duong_di(int i1,int j1,int i2,int j2)
      {
       int  i,x,y,k,j;
       int  flag;
       theway  way;
       flag=dan_nhan(i1,j1,i2,j2);
       if (flag)
           {
    	 for (i=0;i<=dinh[i2][j2];++i)
    	    way[i]=0;
    	 x=i2;
    	 y=j2;
    	 way[dinh[i2][j2]]=x*10+y;
    	 for(i=dinh[i2][j2];i>0;--i)
    	  {
    	    k=0;
    	     while (k<=3)
    	      {
    	       if((dinh[x][y]==dinh[x+a[k]][y+b[k]]+1)&&(x+a[k]>=0)
    	       &&(x+a[k]<=8)&&(y+b[k]<=8)&&(y+b[k]>=0))
    		{
    		  x=x+a[k];
    		  y=y+b[k];
    		  way[i-1]=x*10+y;
    		  k=4;
    		}
    	       else k++;
    	      }
    	  }
    	for (i=0;i<=dinh[i2][j2];++i)
    	 {
    	   x=way[i]/10;
    	   y=way[i]%10;
    	   ballShow(x,y,ball[i1+8][j1+8],1);
    	   delay(5);
    	   clearball(x,y);
    	 }
    	return 1;
          }
        else return 0;
    }
    
    /*__________________________________________________________________________*/
    void process()
    {
       int x,y,mar1;
       int t,h;
       int n;
       mar1=mar2;mar3=mar2;
       randomize();
       mouseshow();
       while (1)
         {
    
           if (kbhit())
           if(getch()==27)   return;
           mouselclick(&x,&y);
           if((_BX==1)&&(x>=LEFT+1)&&(x<=LEFT+41)&&(y>=TOP-75)
    	    &&(y<=TOP-55))
    	    menu(LEFT+1,TOP-58,3,fil,1);
           else if ((_BX==1)&&(x>=LEFT+42)&&(x<=LEFT+82)&&(y>=TOP-75)
    	      &&(y<=TOP-55))
    	    menu(LEFT+42,TOP-58,2,gam,2);
           else if ((_BX==1)&&(x>=LEFT+84)&&(x<=LEFT+124)&&(y>=TOP-75)
    	       &&(y<=TOP-55))
    	   menu(LEFT+84,TOP-58,2,hel,3);
           else  if((_BX==1)&&(x>=LEFT)&&(y>=TOP))
    	   {
    	      ii=(x-LEFT)/40;jj=(y-TOP)/40;
    	      mousehide();
    	      if((ii>=0)&&(ii<9)&&(jj>=0)&&(jj<9))
    		{
    		   if(ball[ii+8][jj+8]>0)
    		     {
    			if(!(co))
    			  {
    			     wait(ii,jj,ball[ii+8][jj+8]);
    			     co=1;ii1=ii;jj1=jj;
    			   }
    			  else if((ii!=ii1)||(jj!=jj1))
    			   {
    			     clearball(ii1,jj1);
    			     ballShow(ii1,jj1,ball[ii1+8][jj1+8],1);
    			     wait(ii,jj,ball[ii+8][jj+8]);
    			     ii1=ii;jj1=jj;
    			   }
    		     }
    		  else if ((co)&&(duong_di(ii1,jj1,ii,jj)))
    		     {
    		       for (h=0;h<=8;++h)
    		       for (t=0;t<=8;++t)
    			ball1[h+8][t+8]=ball[h+8][t+8];
    		       for (t=0;t<=2;++t)
    			{
    			  vtx1[t]=vtx[t];
    			  vty1[t]=vty[t];
    			  vtc1[t]=vtc[t];
    			}
    		       n=0;
    		       for(h=0;h<=8;++h)
    		       for(t=0;t<=8;++t)
    		       if(ball[h+8][t+8]>0)   n+=1;
    		       if(n>=78)   cancle();
    		       if(ball[ii+8][jj+8]<0)
    			{
    			  do
    			   {
    			     h=random(9);
    			     t=random(9);
    			   }
    			  while (ball[h+8][t+8]!=0);
    				ball[h+8][t+8]=-ball[ii+8][jj+8];
    				ballShow(h,t,ball[h+8][t+8],1);
    			}
    		       ball[ii+8][jj+8]=ball[ii1+8][jj1+8];
    		       ball[ii1+8][jj1+8]=0;
    		       ballShow(ii,jj,ball[ii+8][jj+8],1);
    		       clearball(ii1,jj1);
    		       co=0;
    		       mar1=mar2+mark(ii,jj);
    		       if(mar1==mar2)
    			{
    			  for (t=0;t<=2;++t)
    				  vtc[t]=ball[vtx[t]+8][vty[t]+8];
    			  drawBall1(vtx,vty,vtc);
    			  for (t=0;t<=2;++t)
    			  mar1=mar1+mark(vtx[t],vty[t]);
    			  flagEnd=randd(vtx,vty,vtc);
    			}
    		       else
    			{
    			  for(t=0;t<=2;++t)
    			  if (ball[vtx[t]+8][vty[t]+8]<0)
    			  ballShow(vtx[t],vty[t],-ball[vtx[t]+8][vty[t]+8],0);
    			}
    		      if (mar1!=mar2)
    			{
    			  score(mar2,9);
    			  score(mar1,12);
    			  mar3=mar2;
    			  mar2=mar1;
    			}
    		    }
    		    mar3=mar1;
    		 }
    	    }
           mouseshow();
         }
    }
    Đã được chỉnh sửa lần cuối bởi thangtran : 23-12-2007 lúc 08:03 PM. Lý do: Chưa cho code vào tag

  2. #2
    Ngày gia nhập
    10 2006
    Nơi ở
    In Your Bugs
    Bài viết
    823

    Chỉ là đặt các giá trị ban đầu cho các biến thôi, nhưng nếu cậu muốn hỏi đặt để làm gì, vì sao đặt thì có vẻ phải nghiên cứu cài đề bài, và cái thuật toán người viết muốn dùng nữa.

Các đề tài tương tự

  1. Cung cấp giấy ik plus, Paper One, Plus A+, Double A, Giấy Thái Lan, Giấy Bãi Bằng, bìa màu, băng dính, mica các loại
    Gửi bởi dungptvietthanh trong diễn đàn Giới thiệu website, sản phẩm của bạn
    Trả lời: 0
    Bài viết cuối: 07-06-2013, 04:05 PM
  2. Chung cư Đại Thanh giảm sốc 10tr/vnđ cho các căn hộ. giảm và liên tục giảm…!!
    Gửi bởi lanthanh91 trong diễn đàn Giới thiệu website, sản phẩm của bạn
    Trả lời: 0
    Bài viết cuối: 09-10-2012, 10:27 AM
  3. Trả lời: 0
    Bài viết cuối: 06-08-2012, 07:01 PM
  4. Trả lời: 0
    Bài viết cuối: 04-08-2012, 03:08 PM
  5. Trả lời: 0
    Bài viết cuối: 24-05-2012, 04:04 PM

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn