【发布时间】:2012-08-25 02:38:33
【问题描述】:
我试图使用箭头键来左右移动俄罗斯方块方块并旋转,但是当方块落下 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;
}
}
}
【问题讨论】:
-
在设计俄罗斯方块时,我什至不用箭头键,这对我很有用。我刚用过 WASD。
标签: c++ visual-studio-2008 keydown tetris