0

矢印キーを使用してテトリス ブロックを左右に動かして回転させようとしていますが、ブロックが 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;
        }
    }

}
4

1 に答える 1

0

Form1_KeyDown はフォームのコールバックとして登録されていますか? これを実行して確認します:

private: System::Void Form1_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) 
             {
                 System::Console::WriteLine(S"KeyDown is working");

             }
于 2012-08-25T03:39:35.560 に答える