Su 200943147
Dependencies: Gamepad N5110 mbed
Shape/Shape.cpp
- Committer:
- GS00
- Date:
- 2017-04-29
- Revision:
- 5:afa6592a4ba5
- Parent:
- 3:9dd35424cdfe
- Child:
- 6:e919a1fd1eed
File content as of revision 5:afa6592a4ba5:
#include "Shape.h" Shape::Shape() { } void Shape::Init() { srand(time(NULL)); RandomNumber=rand()%7; if(RandomNumber==0) { T_Shape(); RandomNumber=10; } else if(RandomNumber==1) { J_Shape(); RandomNumber=10; } else if(RandomNumber==2) { L_Shape(); RandomNumber=10; } else if(RandomNumber==3) { O_Shape(); RandomNumber=10; } else if(RandomNumber==4) { I_Shape(); RandomNumber=10; } else if(RandomNumber==5) { S_Shape(); RandomNumber=10; } else if(RandomNumber==6) { Z_Shape(); RandomNumber=10; } } void Shape::L_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=1; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::O_Shape() { ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::S_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=1; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::Z_Shape() { ShapeInit[l+1][k+2]=1; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::I_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=1; ShapeInit[l+3][k+1]=0; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=0; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=1; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::J_Shape() { ShapeInit[l+1][k+1]=0; ShapeInit[l+2][k+1]=0; ShapeInit[l+3][k+1]=1; ShapeInit[l+4][k+1]=0; ShapeInit[l+1][k+2]=0; ShapeInit[l+2][k+2]=0; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=1; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::T_Shape() { ShapeInit[l+1][k+2]=1; ShapeInit[l+2][k+2]=1; ShapeInit[l+3][k+2]=1; ShapeInit[l+4][k+2]=0; ShapeInit[l+1][k+3]=0; ShapeInit[l+2][k+3]=1; ShapeInit[l+3][k+3]=0; ShapeInit[l+4][k+3]=0; ShapeInit[l+1][k+4]=0; ShapeInit[l+2][k+4]=0; ShapeInit[l+3][k+4]=0; ShapeInit[l+4][k+4]=0; } void Shape::Update() { int n=14; ShapeArray[x+n][y]=0; ShapeArray[x+1+n][y]=0; ShapeArray[x+2+n][y]=0; ShapeArray[x+3+n][y]=0; ShapeArray[x+4+n][y]=0; ShapeArray[x+5+n][y]=0; ShapeArray[x+n][y+1]=0; ShapeArray[x+5+n][y+1]=0; ShapeArray[x+n][y+2]=0; ShapeArray[x+5+n][y+2]=0; ShapeArray[x+n][y+3]=0; ShapeArray[x+5+n][y+3]=0; ShapeArray[x+n][y+4]=0; ShapeArray[x+5+n][y+4]=0; ShapeArray[x+1+n][y+1]=ShapeInit[l+1][k+1]; ShapeArray[x+2+n][y+1]=ShapeInit[l+2][k+1]; ShapeArray[x+3+n][y+1]=ShapeInit[l+3][k+1]; ShapeArray[x+1+n][y+2]=ShapeInit[l+1][k+2]; ShapeArray[x+2+n][y+2]=ShapeInit[l+2][k+2]; ShapeArray[x+3+n][y+2]=ShapeInit[l+3][k+2]; ShapeArray[x+4+n][y+2]=ShapeInit[l+4][k+2]; ShapeArray[x+1+n][y+3]=ShapeInit[l+1][k+3]; ShapeArray[x+2+n][y+3]=ShapeInit[l+2][k+3]; ShapeArray[x+3+n][y+3]=ShapeInit[l+3][k+3]; ShapeArray[x+4+n][y+3]=ShapeInit[l+4][k+3]; ShapeArray[x+1+n][y+4]=ShapeInit[l+1][k+4]; ShapeArray[x+2+n][y+4]=ShapeInit[l+2][k+4]; ShapeArray[x+3+n][y+4]=ShapeInit[l+3][k+4]; ShapeArray[x+4+n][y+4]=ShapeInit[l+4][k+4]; }