📄 block.cpp
字号:
break;
case RotationDirecttions::WEST:
this->StatusRotation = RotationDirecttions::NORTH;
square2->_Location.X = square1->_Location.X+ squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X ;
square3->_Location.Y = square1->_Location.Y + squareSize;
square4->_Location.X = square1->_Location.X;
square4->_Location.Y = square1->_Location.Y + squareSize*2;
break;
}
break;
case BlockTypes::J:
switch(this->StatusRotation)
{
case RotationDirecttions::NORTH:
this->StatusRotation = RotationDirecttions::EAST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y + squareSize;
square3->_Location.X = square1->_Location.X + squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X + squareSize*2;
square4->_Location.Y = square1->_Location.Y ;
break;
case RotationDirecttions::EAST:
this->StatusRotation = RotationDirecttions::SOUTH;
square2->_Location.X = square1->_Location.X+ squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X ;
square3->_Location.Y = square1->_Location.Y - squareSize;
square4->_Location.X = square1->_Location.X ;
square4->_Location.Y = square1->_Location.Y - squareSize*2;
break;
case RotationDirecttions::WEST:
this->StatusRotation = RotationDirecttions::NORTH;
square2->_Location.X = square1->_Location.X- squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X;
square3->_Location.Y = square1->_Location.Y + squareSize;
square4->_Location.X = square1->_Location.X;
square4->_Location.Y = square1->_Location.Y + squareSize*2;
break;
case RotationDirecttions::SOUTH:
this->StatusRotation = RotationDirecttions::WEST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y - squareSize;
square3->_Location.X = square1->_Location.X - squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X - squareSize*2;
square4->_Location.Y = square1->_Location.Y ;
break;
}
break;
case BlockTypes::Line:
switch(this->StatusRotation)
{
case RotationDirecttions::NORTH:
this->StatusRotation = RotationDirecttions::EAST;
square1->_Location.X = square2->_Location.X - squareSize;
square1->_Location.Y = square2->_Location.Y;
square3->_Location.X = square2->_Location.X + squareSize;
square3->_Location.Y = square2->_Location.Y ;
square4->_Location.X = square2->_Location.X + squareSize*2;
square4->_Location.Y = square2->_Location.Y ;
break;
case RotationDirecttions::EAST:
this->StatusRotation = RotationDirecttions::NORTH;
square1->_Location.X = square2->_Location.X;
square1->_Location.Y = square2->_Location.Y - squareSize;
square3->_Location.X = square2->_Location.X ;
square3->_Location.Y = square2->_Location.Y + squareSize;
square4->_Location.X = square2->_Location.X ;
square4->_Location.Y = square2->_Location.Y + squareSize*2;
break;
}
break;
case BlockTypes::S:
switch(this->StatusRotation)
{
case RotationDirecttions::NORTH:
this->StatusRotation = RotationDirecttions::EAST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y - squareSize;
square3->_Location.X = square1->_Location.X - squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X - squareSize;
square4->_Location.Y = square1->_Location.Y + squareSize;
break;
case RotationDirecttions::EAST:
this->StatusRotation = RotationDirecttions::NORTH;
square2->_Location.X = square1->_Location.X- squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X ;
square3->_Location.Y = square1->_Location.Y + squareSize;
square4->_Location.X = square1->_Location.X + squareSize;
square4->_Location.Y = square1->_Location.Y + squareSize;
break;
}
break;
case BlockTypes::T:
switch(this->StatusRotation)
{
case RotationDirecttions::NORTH:
this->StatusRotation = RotationDirecttions::EAST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y - squareSize;
square3->_Location.X = square1->_Location.X + squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X ;
square4->_Location.Y = square1->_Location.Y + squareSize;
break;
case RotationDirecttions::EAST:
this->StatusRotation = RotationDirecttions::SOUTH;
square2->_Location.X = square1->_Location.X+ squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X ;
square3->_Location.Y = square1->_Location.Y + squareSize;
square4->_Location.X = square1->_Location.X - squareSize;
square4->_Location.Y = square1->_Location.Y ;
break;
case RotationDirecttions::SOUTH:
this->StatusRotation = RotationDirecttions::WEST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y + squareSize;
square3->_Location.X = square1->_Location.X - squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X ;
square4->_Location.Y = square1->_Location.Y - squareSize;
break;
case RotationDirecttions::WEST:
this->StatusRotation = RotationDirecttions::NORTH;
square2->_Location.X = square1->_Location.X- squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X ;
square3->_Location.Y = square1->_Location.Y - squareSize;
square4->_Location.X = square1->_Location.X + squareSize;
square4->_Location.Y = square1->_Location.Y ;
break;
}
break;
case BlockTypes::Z:
switch(this->StatusRotation)
{
case RotationDirecttions::NORTH:
this->StatusRotation = RotationDirecttions::EAST;
square2->_Location.X = square1->_Location.X;
square2->_Location.Y = square1->_Location.Y - squareSize;
square3->_Location.X = square1->_Location.X + squareSize;
square3->_Location.Y = square1->_Location.Y ;
square4->_Location.X = square1->_Location.X + squareSize;
square4->_Location.Y = square1->_Location.Y + squareSize;
break;
case RotationDirecttions::EAST:
this->StatusRotation = RotationDirecttions::NORTH;
square2->_Location.X = square1->_Location.X- squareSize;
square2->_Location.Y = square1->_Location.Y ;
square3->_Location.X = square1->_Location.X;
square3->_Location.Y = square1->_Location.Y - squareSize;
square4->_Location.X = square1->_Location.X + squareSize;
square4->_Location.Y = square1->_Location.Y - squareSize;
break;
}
break;
}
if(!(GameField::IsEmpty((int)square1->_Location.X / squareSize ,(int)square1->_Location.Y / squareSize)
&&GameField::IsEmpty((int)square2->_Location.X / squareSize ,(int)square2->_Location.Y / squareSize)
&&GameField::IsEmpty((int)square3->_Location.X / squareSize ,(int)square3->_Location.Y / squareSize)
&&GameField::IsEmpty((int)square4->_Location.X / squareSize,(int)square4->_Location.Y / squareSize) ))
{
this->StatusRotation = OldStatusRotation;
square1->_Location = OldPosition1;
square2->_Location = OldPosition2;
square3->_Location = OldPosition3;
square4->_Location = OldPosition4;
}
Show();
}
void Block::Show()
{
this->square1->Show(*(this->_engine->hdc),*(this->_engine->info));
this->square2->Show(*(this->_engine->hdc),*(this->_engine->info));
this->square3->Show(*(this->_engine->hdc),*(this->_engine->info));
this->square4->Show(*(this->_engine->hdc),*(this->_engine->info));
}
void Block::Hide()
{
this->square1->Hide(*(this->_engine->hdc),*(this->_engine->info),_engine->BackColor);
this->square2->Hide(*(this->_engine->hdc),*(this->_engine->info),_engine->BackColor);
this->square3->Hide(*(this->_engine->hdc),*(this->_engine->info),_engine->BackColor);
this->square4->Hide(*(this->_engine->hdc),*(this->_engine->info),_engine->BackColor);
}
int Block::Top()
{
return min(square1->_Location.Y,min(square2->_Location.Y,
min(square3->_Location.Y,square4->_Location.Y )));
}
Block::Block(Block const & block)
{
if(&block == this)
return ;
this->_engine = block._engine;
//this->backColors = block.backColors;
this->BlockType = block.BlockType;
//this->foreColor = block.foreColor;
this->squareSize = block.squareSize;
this->StatusRotation = block.StatusRotation;
if(this->square1 != NULL)
delete square1;
square1 = new Square(*block.square1);
if(this->square2 != NULL)
delete square2;
square2 = new Square(*block.square2);
if(this->square3 != NULL)
delete square3;
square3 = new Square(*block.square3);
if(this->square4 != NULL)
delete square4;
square4 = new Square(*block.square4);
}
BlockTypes Block::GetType()
{
return this->BlockType;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -