destinate.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:35k
- #ifndef DESTINATE_H_
- #define DESTINATE_H_
- //-----------------//
- #include "stdlib.h"
- //-----------------//
- const int ROW =24;
- const int COL =14;
- enum VAR;
- struct BlockStruct;
- class Block;
- //----------------//
- void GenerateBlock();
- bool SetArray(Block & block);
- bool ExamArray();
- void BreakBlock();
- void InitArray();
- //----------------//
- enum VAR { LL1,LL2,LL3,LL4,
- LR5,LR6,LR7,LR8,
- C1,C2,C3,C4,
- B,
- LY1,LY2,
- RY1,RY2,
- T1,T2
- };
- //---------------//
- struct BlockStruct
- {
- int red;
- int green;
- int blue;
- bool takeup;
- int x;
- int y;
- };
- BlockStruct Array[ROW][COL];
- //----------------//
- class Block
- {
- public:
- BlockStruct centerpoint;
- VAR kind;
- public:
- Block();
- Block(VAR kind,BlockStruct block);
- void Generate();
- bool LeftOK();
- bool RightOK();
- bool DownOK();
- // bool ShiftOK();
- bool Shift();
- void Left();
- void Right();
- void Down();
- void ChangeBlock();
- void ChangeTrue();
- void ChangeFalse();
- bool Possiable();
- };
- //--------------//
- void InitArray()
- {
- int k=0,p=0;
- //---------------------//
- for(k=0;k<ROW-1;k++)
- for(p=1;p<COL-1;p++)
- Array[k][p].takeup=false;
- //--------------------//
- for(k=0;k<ROW;k++)
- for(p=0;p<COL;p++)
- {
- Array[k][p].red=1;
- Array[k][p].green=1;
- Array[k][p].blue=1;
- }
- //--------------------//
- p=0;
- while(p<ROW)
- {
- Array[p++][0].takeup=true;
- }
- p=0;
- while(p<ROW)
- {
- Array[p++][COL-1].takeup=true;
- }
- p=0;
- while(p<COL)
- {
- Array[ROW-1][p++].takeup=true;
- }
- }
- void BreakBlock()
- {
- int i=1,j=1;
- int k,p;
- for(j=ROW-2;j>=1;j--)
- {
- i=1;
- while(Array[j][i].takeup)
- {
- i++;
- if(i==COL-2)
- {
- for(k=j;k>1;k--)
- {
- p=1;
- while(p<COL-1)
- {
- Array[k][p].takeup=Array[k-1][p].takeup;
- p++;
- }
- }
- p=1;
- while(p<COL-1)
- {
- Array[1][p].takeup=false;
- p++;
- }
- break;
- }
- }
- }
- }
- Block::Block()
- {
- }
- void Block::Generate()
- {
- int i=rand()%19;
- switch(i)
- {
- case 0: kind=LL1;centerpoint.x=1;break;
- case 1: kind=LL2;centerpoint.x=2;break;
- case 2: kind=LL3;centerpoint.x=4;break;
- case 3: kind=LL4;centerpoint.x=1;break;
- case 4: kind=LR5;centerpoint.x=1;break;
- case 5: kind=LR6;centerpoint.x=2;break;
- case 6: kind=LR7;centerpoint.x=4;break;
- case 7: kind=LR8;centerpoint.x=1;break;
- case 8: kind=C1; centerpoint.x=1;break;
- case 9: kind=C2; centerpoint.x=2;break;
- case 10: kind=C3; centerpoint.x=2;break;
- case 11: kind=C4; centerpoint.x=2;break;
- case 12: kind=B; centerpoint.x=1;break;
- case 13: kind=LY1;centerpoint.x=1;break;
- case 14: kind=LY2;centerpoint.x=2;break;
- case 15: kind=RY1;centerpoint.x=1;break;
- case 16: kind=RY2;centerpoint.x=1;break;
- case 17: kind=T1; centerpoint.x=1;break;
- case 18: kind=T2; centerpoint.x=1;break;
- default:
- kind=LL1;
- }
- centerpoint.y=COL/2;
- centerpoint.blue=rand()%255;
- centerpoint.green=rand()%255;
- centerpoint.red=rand()%255;
- }
- Block::Block(VAR kind,BlockStruct block)
- {
- this->kind=kind;
- centerpoint=block;
- }
- /*
- bool Block::LeftOK()
- {
- switch(this->kind)
- {
- case LL1:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y-1].takeup&&!Array[centerpoint.x+3][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LL2:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x-1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
-
- }
- case LL3:
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x-1][centerpoint.y-1].takeup&&!Array[centerpoint.x-2][centerpoint.y-1].takeup&&!Array[centerpoint.x-3][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case LL4:
- {
- if(centerpoint.y-4<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-4].takeup&&!Array[centerpoint.x+1][centerpoint.y-4].takeup)
- return true;
- else
- return false;
- }
- case LR5:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y-1].takeup&&!Array[centerpoint.x+3][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LR6:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x-1][centerpoint.y-1].takeup&&!Array[centerpoint.x][centerpoint.y-1].takeup)
- return true;
- else
- return false;
-
- }
- case LR7:
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-2].takeup&&!Array[centerpoint.x-1][centerpoint.y-1].takeup&&!Array[centerpoint.x-2][centerpoint.y-1].takeup&&!Array[centerpoint.x-3][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LR8:
- {
- if(centerpoint.y-4<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-4].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case C1 :
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case C2 :
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x-1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case C3 :
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x-1][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case C4 :
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-2].takeup&&!Array[centerpoint.x-1][centerpoint.y-2].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case B :
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LY1:
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case LY2:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x-1][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case RY1:
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case RY2:
- {
- if(centerpoint.y-2<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup&&!Array[centerpoint.x+2][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case T1 :
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case T2 :
- {
- if(centerpoint.y-1<=0)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- default:
- {
- return false;
- }
-
- }
- }*/
- /*
- bool Block::RightOK()
- {
- switch(this->kind)
- {
- case LL1:
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup&&!Array[centerpoint.x+3][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case LL2:
- {
- if(centerpoint.y+3>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+4].takeup&&!Array[centerpoint.x-1][centerpoint.y+4].takeup)
- return true;
- else
- return false;
-
- }
- case LL3:
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x-1][centerpoint.y+1].takeup&&!Array[centerpoint.x-2][centerpoint.y+1].takeup&&!Array[centerpoint.x-3][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LL4:
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup)
- return true;
- else
- return false;
- }
- case LR5:
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup&&!Array[centerpoint.x+3][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LR6:
- {
- if(centerpoint.y+3>=COL-2)
- return false;
- if(!Array[centerpoint.x-1][centerpoint.y+1].takeup&&!Array[centerpoint.x][centerpoint.y+4].takeup)
- return true;
- else
- return false;
-
- }
- case LR7:
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x-1][centerpoint.y+1].takeup&&!Array[centerpoint.x-2][centerpoint.y+1].takeup&&!Array[centerpoint.x-3][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LR8:
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case C1 :
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case C2 :
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x-1][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case C3 :
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x-1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case C4 :
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x-1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case B :
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case LY1:
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LY2:
- {
- if(centerpoint.y+1>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x-1][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case RY1:
- {
- if(centerpoint.y+2>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+3].takeup)
- return true;
- else
- return false;
- }
- case RY2:
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+2][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case T1 :
- {
- if(centerpoint.y>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case T2 :
- {
- if(centerpoint.y+2>=COL-2)
- return false;
- if(!Array[centerpoint.x][centerpoint.y+3].takeup)
- return true;
- else
- return false;
- }
- default:
- {
- return false;
- }
-
- }
- }
- */
- // only judge whether it can manipulate not do action
- //只判断不修改centerpoint的值.
- /*
- bool Block::DownOK()
- {
- switch(this->kind)
- {
- case LL1:
- {
- if(centerpoint.x+3>=ROW-1)
- return false;
- if(!Array[centerpoint.x+4][centerpoint.y].takeup&&!Array[centerpoint.x+4][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LL2:
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+3].takeup)
- return true;
- else
- return false;
-
- }
- case LL3:
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x-2][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LL4:
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y-3].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case LR5:
- {
- if(centerpoint.x+3>=ROW-1)
- return false;
- if(!Array[centerpoint.x+4][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LR6:
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup&&!Array[centerpoint.x+1][centerpoint.y+3].takeup)
- return true;
- else
- return false;
-
- }
- case LR7:
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case LR8:
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y-3].takeup&&!Array[centerpoint.x+1][centerpoint.y-2].takeup&&!Array[centerpoint.x+1][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case C1 :
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case C2 :
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case C3 :
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x][centerpoint.y-1].takeup&&!Array[centerpoint.x][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case C4 :
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y-1].takeup&&!Array[centerpoint.x+1][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case B :
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LY1:
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y-1].takeup&&!Array[centerpoint.x+2][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case LY2:
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup)
- return true;
- else
- return false;
- }
- case RY1:
- {
- if(centerpoint.x+1>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+2][centerpoint.y+1].takeup&&!Array[centerpoint.x+2][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- case RY2:
- {
- if(centerpoint.x+2>=ROW-1)
- return false;
- if(!Array[centerpoint.x+2][centerpoint.y].takeup&&!Array[centerpoint.x+3][centerpoint.y-1].takeup)
- return true;
- else
- return false;
- }
- case T1 :
- {
- if(centerpoint.x+2>=ROW-1)
- return false;
- if(!Array[centerpoint.x+3][centerpoint.y].takeup)
- return true;
- else
- return false;
- }
- case T2 :
- {
- if(centerpoint.x>=ROW-1)
- return false;
- if(!Array[centerpoint.x+1][centerpoint.y].takeup&&!Array[centerpoint.x+1][centerpoint.y+1].takeup&&!Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return true;
- else
- return false;
- }
- default:
- {
- return false;
- }
- }
- }*/
- bool Block::LeftOK()
- {
- ChangeFalse();
- centerpoint.y-=1;
- if(Possiable())
- {
- centerpoint.y+=1;
- return true;
- }
- else
- {
- centerpoint.y+=1;
- return false;
- }
- }
- bool Block::RightOK()
- {
- ChangeFalse();
- centerpoint.y+=1;
- if(Possiable())
- {
- centerpoint.y-=1;
- return true;
- }
- else
- {
- centerpoint.y-=1;
- return false;
- }
- }
- bool Block::DownOK()
- {
- ChangeFalse();
- centerpoint.x+=1;
- if(Possiable())
- {
- centerpoint.x-=1;
- return true;
- }
- else
- {
- centerpoint.x-=1;
- return false;
- }
- }
- bool Block::Shift()
- {
- ChangeFalse();
- switch(kind)
- {
- case LL1:
- {
- centerpoint.x+=2;
- centerpoint.y--;
- kind=LL2;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=2;
- centerpoint.y++;
- kind=LL1;
- return false;
- }
-
- }
- case LL2:
- {
- centerpoint.y+=1;
- centerpoint.x+=2;
- kind=LL3;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y-=1;
- centerpoint.x-=2;
- kind=LL2;
- return false;
- }
- }
- case LL3:
- {
- centerpoint.y+=2;
- kind=LL4;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y-=2;
- kind=LL3;
- return false;
- }
- }
- case LL4:
- {
- centerpoint.y-=3;
- //centerpoint.x-=2;
- kind=LL1;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y+=3;
- // centerpoint.x+=2;
- kind=LL4;
- return false;
- }
- }
- case LR5:
- {
-
- centerpoint.x+=3;
- kind=LR6;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=3;
- kind=LR5;
- return false;
- }
- }
- case LR6:
- {
- kind=LR7;
- centerpoint.x+=1;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=1;
- kind=LR6;
- return false;
- }
- }
- case LR7:
- {
- centerpoint.y+=2;
- centerpoint.x-=1;
- kind=LR8;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y-=2;
- centerpoint.x+=1;
- kind=LR7;
- return false;
- }
- }
- case LR8:
- {
- centerpoint.y-=3;
- centerpoint.x-=2;
- kind=LR5;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y+=3;
- centerpoint.x+=2;
- kind=LR8;
- return false;
- }
- }
- case C1 :
- {
- centerpoint.y-=1;
- kind=C2;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y+=1;
- kind=C1;
- return false;
- }
- }
- case C2 :
- {
- centerpoint.x+=1;
- centerpoint.y+=1;
- kind=C3;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=1;
- centerpoint.y-=1;
- kind=C2;
- return false;
- }
- }
- case C3 :
- {
- centerpoint.x-=1;
- kind=C4;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x+=1;
- kind=C3;
- return false;
- }
- }
- case C4 :
- {
- kind=C1;
- if(Possiable())
- return true;
- else
- {
- kind=C4;
- return false;
- }
- }
- case B :
- {
- return true;
- }
- case LY1:
- {
- centerpoint.y-=1;
- kind=LY2;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y+=1;
- kind=LY1;
- return false;
- }
- }
- case LY2:
- {
- centerpoint.y+=1;
- kind=LY1;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y-=1;
- kind=LY2;
- return false;
- }
- }
- case RY1:
- {
- centerpoint.y+=1;
- centerpoint.x-=1;
- kind=RY2;
- if(Possiable())
- return true;
- else
- {
- centerpoint.y-=1;
- centerpoint.x+=1;
- kind=RY1;
- return false;
- }
- }
- case RY2:
- {
- centerpoint.x+=1;
- centerpoint.y-=1;
- kind=RY1;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=1;
- centerpoint.y+=1;
- kind=RY2;
- return false;
- }
- }
- case T1 :
- {
- centerpoint.x+=1;
- centerpoint.y-=1;
- kind=T2;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x-=1;
- centerpoint.y+=1;
- kind=T1;
- return false;
- }
- }
- case T2 :
- {
- centerpoint.x-=1;
- centerpoint.y+=1;
- kind=T1;
- if(Possiable())
- return true;
- else
- {
- centerpoint.x+=1;
- centerpoint.y-=1;
- kind=T2;
- return false;
- }
- }
- default:
- {
- return false;
- }
- }
- }
- void Block::ChangeBlock()
- {
- switch(kind)
- {
- case LL1:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+2][centerpoint.y]=centerpoint;
- Array[centerpoint.x+3][centerpoint.y]=centerpoint;
- Array[centerpoint.x+3][centerpoint.y+1]=centerpoint;
- break;
- }
- case LL2:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x][centerpoint.y+2]=centerpoint;
- Array[centerpoint.x][centerpoint.y+3]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y+3]=centerpoint;
- break;
- }
- case LL3:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y]=centerpoint;
- Array[centerpoint.x-2][centerpoint.y]=centerpoint;
- Array[centerpoint.x-3][centerpoint.y]=centerpoint;
- Array[centerpoint.x-3][centerpoint.y-1]=centerpoint;
- break;
- }
- case LL4:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x][centerpoint.y-2]=centerpoint;
- Array[centerpoint.x][centerpoint.y-3]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y-3]=centerpoint;
- break;
- }
- case LR5:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+2][centerpoint.y]=centerpoint;
- Array[centerpoint.x+3][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- break;
- }
- case LR6:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x][centerpoint.y+2]=centerpoint;
- Array[centerpoint.x][centerpoint.y+3]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y]=centerpoint;
- break;
- }
- case LR7:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y]=centerpoint;
- Array[centerpoint.x-2][centerpoint.y]=centerpoint;
- Array[centerpoint.x-3][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y-1]=centerpoint;
- break;
- }
- case LR8:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x][centerpoint.y-2]=centerpoint;
- Array[centerpoint.x][centerpoint.y-3]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- break;
- }
- case C1 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+1]=centerpoint;
- break;
- }
- case C2 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+1]=centerpoint;
- break;
- }
- case C3 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y+1]=centerpoint;
- break;
- }
- case C4 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y-1]=centerpoint;
- break;
- }
- case B :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+1]=centerpoint;
- break;
- }
- case LY1:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y-1]=centerpoint;
- break;
- }
- case LY2:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x-1][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+1]=centerpoint;
- break;
- }
- case RY1:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y+2]=centerpoint;
- break;
- }
- case RY2:
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y-1]=centerpoint;
- Array[centerpoint.x+2][centerpoint.y-1]=centerpoint;
- break;
- }
- case T1 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x+1][centerpoint.y]=centerpoint;
- Array[centerpoint.x+2][centerpoint.y]=centerpoint;
- break;
- }
- case T2 :
- {
- Array[centerpoint.x][centerpoint.y]=centerpoint;
- Array[centerpoint.x][centerpoint.y+1]=centerpoint;
- Array[centerpoint.x][centerpoint.y+2]=centerpoint;
- break;
- }
- default:
- {
- return;
- }
- }
- }
- void Block::Left()
- {
- if(LeftOK())
- centerpoint.y--;
- }
- void Block::Right()
- {
- if(RightOK())
- centerpoint.y++;
- }
- void Block::Down()
- {
- if(DownOK())
- centerpoint.x++;
- }
- void Block::ChangeTrue()
- {
- centerpoint.takeup=true;
- ChangeBlock();
- }
- void Block::ChangeFalse()
- {
- centerpoint.takeup=false;
- ChangeBlock();
- }
- bool Block::Possiable()
- {
- switch(kind)
- {
- case LL1:
- {
- if(centerpoint.x+3>=ROW-1||centerpoint.y<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+2][centerpoint.y].takeup||Array[centerpoint.x+3][centerpoint.y].takeup||Array[centerpoint.x+3][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case LL2:
- {
- if(centerpoint.x>=ROW-1||centerpoint.y<=0||centerpoint.y+3>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x][centerpoint.y+2].takeup||Array[centerpoint.x][centerpoint.y+3].takeup||Array[centerpoint.x-1][centerpoint.y+3].takeup)
- return false;
- return true;
- }
- case LL3:
- {
- if(centerpoint.x>=ROW-1||centerpoint.y-1<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y].takeup||Array[centerpoint.x-2][centerpoint.y].takeup||Array[centerpoint.x-3][centerpoint.y].takeup||Array[centerpoint.x-3][centerpoint.y-1].takeup)
- return false;
- return true;
- }
- case LL4:
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y-3<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y-1].takeup||Array[centerpoint.x][centerpoint.y-2].takeup||Array[centerpoint.x][centerpoint.y-3].takeup||Array[centerpoint.x+1][centerpoint.y-3].takeup)
- return false;
- return true;
- }
- case LR5:
- {
- if(centerpoint.x+3>=ROW-1||centerpoint.y<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+2][centerpoint.y].takeup||Array[centerpoint.x+3][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case LR6:
- {
- if(centerpoint.x>=ROW-1||centerpoint.y<=0||centerpoint.y+3>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x][centerpoint.y+2].takeup||Array[centerpoint.x][centerpoint.y+3].takeup||Array[centerpoint.x-1][centerpoint.y].takeup)
- return false;
- return true;
- }
- case LR7:
- {
- if(centerpoint.x>=ROW-1||centerpoint.y-1<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y].takeup||Array[centerpoint.x-2][centerpoint.y].takeup||Array[centerpoint.x-3][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y-1].takeup)
- return false;
- return true;
- }
- case LR8:
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y-3<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y-1].takeup||Array[centerpoint.x][centerpoint.y-2].takeup||Array[centerpoint.x][centerpoint.y-3].takeup||Array[centerpoint.x+1][centerpoint.y].takeup)
- return false;
- return true;
- }
- case C1 :
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y-1<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y-1].takeup||Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case C2 :
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y+1].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case C3 :
- {
- if(centerpoint.x>=ROW-1||centerpoint.y-1<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y-1].takeup||Array[centerpoint.x-1][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case C4 :
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y-1<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y-1].takeup||Array[centerpoint.x][centerpoint.y-1].takeup||Array[centerpoint.x+1][centerpoint.y-1].takeup)
- return false;
- return true;
- }
- case B :
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case LY1:
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y-1<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y-1].takeup)
- return false;
- return true;
- }
- case LY2:
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y<=0||centerpoint.y+1>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x-1][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y+1].takeup)
- return false;
- return true;
- }
- case RY1:
- {
- if(centerpoint.x+1>=ROW-1||centerpoint.y<=0||centerpoint.y+2>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y+1].takeup||Array[centerpoint.x+1][centerpoint.y+2].takeup)
- return false;
- return true;
- }
- case RY2:
- {
- if(centerpoint.x+2>=ROW-1||centerpoint.y-1<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y-1].takeup||Array[centerpoint.x+2][centerpoint.y-1].takeup)
- return false;
- return true;
- }
- case T1 :
- {
- if(centerpoint.x+2>=ROW-1||centerpoint.y<=0||centerpoint.y>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x+1][centerpoint.y].takeup||Array[centerpoint.x+2][centerpoint.y].takeup)
- return false;
- return true;
- }
- case T2 :
- {
- if(centerpoint.x>=ROW-1||centerpoint.y<=0||centerpoint.y+2>=COL-1)
- return false;
- if(Array[centerpoint.x][centerpoint.y].takeup||Array[centerpoint.x][centerpoint.y+1].takeup||Array[centerpoint.x][centerpoint.y+2].takeup)
- return false;
- return true;
- }
- default:
- {
- return false;
- }
- }
- }
- bool ExamArray()
- {
- int i=1;
- for(i=1;i<COL-1;i++)
- {
- if(Array[0][i].takeup==true)
- {
- return false; // dead
- }
- }
- return true;// alive
- }
- bool SetArray(Block & block )
- {
- if(!block.LeftOK()&&!block.RightOK()&&!block.DownOK())
- {
- block.ChangeTrue();
- return false; // the block is nonactive
- //it should generate new block
- }
- return true; // the block is still active;
- }
- #endif