تبلیغات
amirali mirsajadi - کد ++c بازی تتریس
#include <cstdlib>
#include <iostream>
#include <graphics.h>
#include <fstream.h>
using namespace std;



struct kh{
       int x1;
       int y1;
       int x2;
       int y2;
       };


       
void khane(kh a,int b)
{
     setcolor(b);
     rectangle(a.x1,a.y1,a.x2,a.y2);
     setfillstyle(1,b);
     floodfill(a.x1+2,a.y1+2,b);
}

void sh1(kh a,int z,int p)
{
     khane(a,p);
}

void sh2(kh a,int z,int p)
{
     khane(a,p);
     kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
     khane(b,p);
     kh c;
     c.x1=a.x1-z;
     c.y1=a.y1;
     c.x2=a.x2-z;
     c.y2=a.y2;
     khane(c,p);
     kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
     khane(d,p);
}

void sh3(kh a,int z,int p)
{
     khane(a,p);
     kh b;
     b.x1=a.x1;
     b.y1=a.y1-z;
     b.x2=a.x2;
     b.y2=a.y2-z;
     khane(b,p);
     kh c;
     c.x1=a.x1;
     c.y1=a.y1-2*z;
     c.x2=a.x2;
     c.y2=a.y2-2*z;
     khane(c,p);
     kh d;
     d.x1=a.x1;
     d.y1=a.y1-3*z;
     d.x2=a.x2;
     d.y2=a.y2-3*z;
     khane(d,p);
}

void sh4(kh a,int z,int p)
{
     khane(a,p);
     kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
     khane(b,p);
     kh c;
     c.x1=a.x1;
     c.y1=a.y1-z;
     c.x2=a.x2;
     c.y2=a.y2-z;
     khane(c,p);
     kh d;
     d.x1=a.x1+z;
     d.y1=a.y1-z;
     d.x2=a.x2+z;
     d.y2=a.y2-z;
     khane(d,p);
}

void sh5(kh a,int z,int p)
{
     khane(a,p);
     kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
     khane(b,p);
     kh c;
     c.x1=a.x1-z;
     c.y1=a.y1;
     c.x2=a.x2-z;
     c.y2=a.y2;
     khane(c,p);
     kh d;
     d.x1=a.x1+z;
     d.y1=a.y1-z;
     d.x2=a.x2+z;
     d.y2=a.y2-z;
     khane(d,p);
}

void sh6(kh a,int z, int p)
{
     khane(a,p);
     kh b;
     b.x1=a.x1;
     b.y1=a.y1-z;
     b.x2=a.x2;
     b.y2=a.y2-z;
     khane(b,p);
     kh c;
     c.x1=a.x1+z;
     c.y1=a.y1-z;
     c.x2=a.x2+z;
     c.y2=a.y2-z;
     khane(c,p);
     kh d;
     d.x1=a.x1+z;
     d.y1=a.y1-2*z;
     d.x2=a.x2+z;
     d.y2=a.y2-2*z;
     khane(d,p);
    
}
ofstream fout("poryakhali.txt");

void por(kh a)
{
     fout<<a.x1<<endl<<a.x2<<endl<<a.y1<<endl<<a.y2<<endl;
}

void pORe(kh a)
{ofstream fgir("pe.txt");
     fgir<<a.x1<<endl<<a.x2<<endl<<a.y1<<endl<<a.y2<<endl;
}
 
bool ist(kh a,int q,int z)
{    int s=0,t=0,u=0,v=0;
     int m=0,n=0,o=0,p=0;
     ifstream fin("poryakhali.txt");
     ifstream fbin("pe.txt");
                            fbin>>m;
                            fbin>>n;
                            fbin>>o;
                            fbin>>p;   
     //************************
     if(q==1){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m){
     if(t==n){
     if(u==o+z){
     if(v==p+z){
     return true;}}}}
                                                                     
                                                                    
                                                                 
     }

     return false;}
     //************************
     if(q==2){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m||s==m+z||s==m-z){
     if(t==n||s==m+z||s==m-z){
     if(u==o+z){
     if(v==p+30){
     return true;}}}}
                                                                     
                                                                    
                                                                
     }return false;}
     //************************
      if(q==3){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m){
     if(t==n){
     if(u==o+z){
     if(v==p+z){
     return true;}}}}
                                                                     
                                                                    
                                                                 
     }

     return false;}
      //************************
     if(q==4){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m||s==m+z){
     if(t==n||t==n+z){
     if(u==o+z){
     if(v==p+z){
     return true;}}}}
                                                                     
                                                                    
                                                                 
     }

     return false;}
      //************************
     if(q==5){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m||s==m+z||s==m-z){
     if(t==n||s==m+z||s==m-z){
     if(u==o+z){
     if(v==p+z){
     return true;}}}}
                                                                     
                                                                    
                                                                 
     }

     return false;}
      //************************
     if(q==6){
     for(int i=1;i<=800;i++)
     {
    
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>v;
                           
     if(s==m){
     if(t==n){
     if(u==o+z){
     if(v==p+z){
     return true;}}}}
     if(u==o){
     if(v==p){
     if(s==m+z){
     if(t==n+z){
     return true;}}}}                                                                
                                                                    
                                                                 
     }

     return false;}
     //**************************
   
}
    
void kenareham(kh a,int z,char v)
{
     int s=0,t=0,u=0,w=0;
     ifstream fin("poryakhali.txt");
     for(int i=1;i<=800;i++)
     {
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>w;
    
     if(a.x1-z==s)
     {
                  if(v=='a')
                  {
                            a.x1=a.x1+2*z;
                            a.x2=a.x2+z;
                  }
     }
     if(a.x2+z==s)
     {
                  if(v=='d')
                  {
                            a.x1=a.x1-z;
                            a.x2=a.x2-z;
                  }
     }
    
     }     
}
int f=0;

//------------------------------------------------------------------------------
void emtiaz()
{
     int s=0,t=0,u=0,w=0,c=0;
     kh g,h,e;
     ifstream fin("poryakhali.txt");
     for(int i=1;i<=800;i++)
     {
     fin>>s;
     fin>>t;
     fin>>u;
     fin>>w;
     if(w==600)
               c++;
               }
     if(c==10){
     f=f+10;
     cout<<f<<endl;
     kh a;
     for(int j=0;j<10;j++){
     a.x1=30*j;
     a.x2=30*j+30;
     a.y1=570;
     a.y2=600;
     khane(a,15);}
     /*for(int k=0;k<10;k++)
     {                  for(int l=19;l>0;l--)
                        {
                                         g.x1=k*30;
                                         g.x2=k*30+30;
                                         g.y1=l*30;
                                         g.y2=l*30+30;
                                         h.x1=k*30;
                                         h.x2=k*30+30;
                                         h.y1=l*30-30;
                                         h.y2=l*30;
                                         e.x1=h.x1;
                                         e.y1=h.y1;
                                         e.x2=h.x2;
                                         e.y2=h.y2;
                                         h.x1=g.x1;
                                         h.y1=g.y1;
                                         h.x2=g.x2;
                                         h.y1=g.y2;
                                         g.x1=e.x1;
                                         g.y1=e.y1;
                                         g.x2=e.x2;
                                         g.y2=e.y2;
                                         khane(g,15);
                                         khane(e,15);
                                        
                                        
                        }
     }
    
     */
    
     }    
                    
    
}
//------------------------------------------------------------------------------

void toop(int q,kh a,int z)
 {    char v;
      int s=0;
              kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
               kh c;
     c.x1=a.x1-z;
     c.y1=a.y1;
     c.x2=a.x2-z;
     c.y2=a.y2;
               kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
                 kh e;
     e.x1=a.x1;
     e.y1=a.y1-2*z;
     e.x2=a.x2;
     e.y2=a.y2-2*z;
                   kh f;
     f.x1=a.x1;
     f.y1=a.y1-3*z;
     f.x2=a.x2;
     f.y2=a.y2-3*z;
                   kh g;
     g.x1=a.x1+z;
     g.y1=a.y1-z;
     g.x2=a.x2+z;
     g.y2=a.y2-z;
                 kh h;
     h.x1=a.x1+z;
     h.y1=a.y1-2*z;
     h.x2=a.x2+z;
     h.y2=a.y2-2*z;
////////////////////////////
  if(q==1){
  while(s==0){                             
            sh1(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+z;
                      a.y2=a.y2+z;}
            }
            }
            if(a.x1<0){
                           a.x1=0;
                           a.x2=30;}
            if(a.x2>300){  a.x2=300;
                           a.x1=270;}
            kenareham(a,z,v);
            sh1(a,z,2);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);
          
 

    }
 
            sh1(a,z,2);
            por(a);
           emtiaz(); return;
            }
//////////////////////////////////////
          
              if(q==2){
  while(s==0)  {        
            sh2(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+30;
                      a.y2=a.y2+30;}
            }
            }
             if(a.x1<30){
                           a.x1=30;
                           a.x2=60;}
            if(a.x2>270){  a.x2=270;
                           a.x1=240;}
            kenareham(a,z,v);
            sh2(a,z,1);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);
}
 
            sh2(a,z,1); 
            por(a);
                      kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
               kh c;
     c.x1=a.x1-z;
     c.y1=a.y1;
     c.x2=a.x2-z;
     c.y2=a.y2;
               kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
            por(b);
            por(c);
            por(d);           
            emtiaz();return;
            }
///////////////////////////////////////          
              if(q==3){
  while(s==0)     {     
            sh3(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+30;
                      a.y2=a.y2+30;}
            }
            }
             if(a.x1<0){
                           a.x1=0;
                           a.x2=30;}
            if(a.x2>300){  a.x2=300;
                           a.x1=270;}
            kenareham(a,z,v);
            sh3(a,z,4);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);

    }
 
            sh3(a,z,4);         
            por(a);
                      kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
                 kh e;
     e.x1=a.x1;
     e.y1=a.y1-2*z;
     e.x2=a.x2;
     e.y2=a.y2-2*z;
                   kh f;
     f.x1=a.x1;
     f.y1=a.y1-3*z;
     f.x2=a.x2;
     f.y2=a.y2-3*z;
                  
            por(d);
            por(e);
            por(f);   
            emtiaz();return;
            }
///////////////////////////////////////
              if(q==4){
  while(s==0)     {     
            sh4(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+30;
                      a.y2=a.y2+30;}
            }
            }
             if(a.x1<0){
                           a.x1=0;
                           a.x2=30;}
            if(a.x2>270){  a.x2=270;
                           a.x1=240;}
            kenareham(a,z,v);
            sh4(a,z,14);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);
}
 
            sh4(a,z,14);      
            por(a);
                   kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
                  kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
                 kh g;
     g.x1=a.x1+z;
     g.y1=a.y1-z;
     g.x2=a.x2+z;
     g.y2=a.y2-z;    
            por(b);
            por(d);
            por(g);     
            emtiaz();return;
            }
////////////////////////////////////////////
              if(q==5){
  while(s==0)   {       
            sh5(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+30;
                      a.y2=a.y2+30;}
            }
            }
             if(a.x1<30){
                           a.x1=30;
                           a.x2=60;}
            if(a.x2>270){  a.x2=270;
                           a.x1=240;}
            kenareham(a,z,v);
            sh5(a,z,8);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);

    }
 
            sh5(a,z,8);             
            por(a);
            kh b;
     b.x1=a.x1+z;
     b.y1=a.y1;
     b.x2=a.x2+z;
     b.y2=a.y2;
               kh c;
     c.x1=a.x1-z;
     c.y1=a.y1;
     c.x2=a.x2-z;
     c.y2=a.y2;
                   kh g;
     g.x1=a.x1+z;
     g.y1=a.y1-z;
     g.x2=a.x2+z;
     g.y2=a.y2-z;
            por(b);
            por(c);
            por(g);
           emtiaz(); return;
            }
////////////////////////////////////////////////
              if(q==6){
  while(s==0)  {        
            sh6(a,z,15);
            a.y1++;
            a.y2++;
            if(kbhit()){
            v=getch();
            if(v=='a')
            {     a.x1=a.x1-z;
                  a.x2=a.x2-z;
            }
            if(v=='d')
            {     a.x1=a.x1+z;
                  a.x2=a.x2+z;
            }
            if(v=='s')
            {if(a.y2<=570)
                      {a.y1=a.y1+30;
                      a.y2=a.y2+30;}
            }
            }
             if(a.x1<0){
                           a.x1=0;
                           a.x2=30;}
            if(a.x2>270){  a.x2=270;
                           a.x1=240;}
            kenareham(a,z,v);
            sh6(a,z,3);
            if(a.y2==600)
                         s=1;
            pORe(a);
            if(ist(a,q,z)==true)
                            s=1;
            delay(15);

    }
 
            sh6(a,z,3);             
            por(a);
               kh d;
     d.x1=a.x1;
     d.y1=a.y1-z;
     d.x2=a.x2;
     d.y2=a.y2-z;
                   kh g;
     g.x1=a.x1+z;
     g.y1=a.y1-z;
     g.x2=a.x2+z;
     g.y2=a.y2-z;
                 kh h;
     h.x1=a.x1+z;
     h.y1=a.y1-2*z;
     h.x2=a.x2+z;
     h.y2=a.y2-2*z;
            por(d);
            por(g);
            por(h);
           emtiaz();return;
            }
}
////////////////////////////////////

void tet(kh a,int z)
{
     int q=rand()%6+1;
     toop(q,a,z);
     tet(a,z);
    
}
    


int main(int argc, char *argv[])
{
    srand(time(0));
    int t[10][20];
  int x=300,y=0;
    int z=30;
    initwindow(10*z,20*z);
    setfillstyle(1,15);
    floodfill(1,1,15);
    kh a;
    a.x1=5*z;
    a.y1=0*z;
    a.x2=6*z;
    a.y2=1*z;
    tet(a,z);
   
   

   
   

    system("PAUSE");
    return EXIT_SUCCESS;
}
 



طبقه بندی: برنامه نویسی،

تاریخ : پنجشنبه 29 فروردین 1392 | 02:34 ب.ظ | نویسنده : امیرعلی میرسجادی | نظرات