C++ 俄罗斯方块游戏C+中调用对象方法的箭头键+;视觉2008
我试着用箭头键左右移动俄罗斯方块并旋转,但当方块从游戏网格上掉下来时,它不起作用。这是我的密码 //这是我在计时器处理程序中的游戏周期C++ 俄罗斯方块游戏C+中调用对象方法的箭头键+;视觉2008,c++,visual-studio-2008,keydown,tetris,C++,Visual Studio 2008,Keydown,Tetris,我试着用箭头键左右移动俄罗斯方块并旋转,但当方块从游戏网格上掉下来时,它不起作用。这是我的密码 //这是我在计时器处理程序中的游戏周期 private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) { mainGameBoard->drawGrid(); newBlock->draw();
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
}
}
下面是我使用箭头键移动和旋转块的代码,move方法和rotate方法位于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++的学生。这是我的MaveFET()方法:< /P>
void块::moveLeft()
{
数组^temporaryCopy=gcnew数组(4);
对于(int i=0;i长度;i++)
{
//设定未来行动
临时副本[i].X=mySquares[i].X-1;
临时复制[i].Y=mySquares[i].Y;
}
if(checkBounds(temporaryCopy)==true)
{
对于(int i=0;i长度;i++)
{
mySquares[i].X=临时副本[i].X;
mySquares[i].Y=临时副本[i].Y;
}
}
}
是否将Form1\u KeyDown调节为表单的回调?
执行此操作以检查:
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
System::Console::WriteLine(S"KeyDown is working");
}
当我设计俄罗斯方块时,我甚至不用担心箭头键。我刚刚使用了WASD。我假设控制台窗口没有显示,所以替换System::console::WriteLine(S“KeyDown正在工作”);使用MessageBox::Show(“keydown”);如果它不工作,那么问题是您没有将函数绑定到KeyDown事件。将其添加到表单的InitilizeComponent函数:this->KeyDown+=gcnew System::Windows::Forms::KeyEventHandler(this,&Form1::Form1\u KeyDown);
private: System::Void Form1_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
System::Console::WriteLine(S"KeyDown is working");
}