我试图使用箭头键左右移动俄罗斯方块,并旋转,但它不工作,而块下降gameGrid . 这是我的代码 .
//这是我在计时器处理程序中的游戏周期
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
mainGameBoard->drawGrid();
newBlock->draw();
newBlock->moveDown();
if(newBlock->canMoveDown()==false)
{
//If block hits bottom or block, add block to grid
newBlock->addMySelfToGameBoard();
//Update the grid by deleting full rows & move
//the game grid down
mainGameBoard->updateGrid();
//Create new block
//Havnt sorted yet
}
}
这是我使用箭头键移动和旋转块的代码,移动方法和旋转方法都在TTetrisBlock类中 .
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(e->KeyData == Keys::Left)
{
newBlock->moveLeft();
}
if(e->KeyData == Keys::Right)
{
newBlock->moveRight();
}
if(e->KeyData == Keys::Up)
{
newBlock->rotate();
}
}
//现在当块在计时器上向下移动游戏网格时,按下时箭头键不移动对象 . 但如果我在计时器中放入newBlock-> moveLeft(),则该块将开始向左移动 . 所以我的moveLeft()方法正常工作 . 请帮助一些 - 我是一名学习C的学生 . 这是我的moveLeft()方法:
void TTetrisBlock::moveLeft()
{
array<Point>^ temporaryCopy = gcnew array<Point>(4);
for(int i=0;i<mySquares->Length;i++)
{
//Set future move
temporaryCopy[i].X = mySquares[i].X-1;
temporaryCopy[i].Y = mySquares[i].Y;
}
if(checkBounds(temporaryCopy) == true)
{
for(int i=0;i<temporaryCopy->Length;i++)
{
mySquares[i].X = temporaryCopy[i].X;
mySquares[i].Y = temporaryCopy[i].Y;
}
}
}
1 回答
是Form1_KeyDown重新注册为表单的回调?这样做来检查: