将来の移動が合法であるかどうかを確認するためのコードは次のとおりです。私はその合法的な移動を想定し、mySquares 配列にコピーしました。次に、フォーム内のゲーム サイクル セットと次のタイマー ハンドラーでこのメソッドを呼び出します。
canvas->drawGrid();
testBlock->drawBlock();
testBlock->moveDown();//this method has checkBounds for when hit sides, top & bottom
if(newBlock->canMoveDown()==false)
{
newBlock->addMySelfToGameBoard();
mainGameBoard->updateGrid();
}
//timer1 handler finish
bool TTetrisBlock::canMoveDown()
{
array<Point>^ temporaryCopy = gcnew array<Point>(4);
bool canGoDown = true;
for(int i=0;i<mySquares->Length;i++)
{
//Set future move
temporaryCopy[i].X = mySquares[i].X;
temporaryCopy[i].Y = mySquares[i].Y+1;
}
//Check if future move cells are full, if not assign values to mySquares
//Check if future move is legal
for(int j=0;j<temporaryCopy->Length;j++)
{
if(gameBoard->isCellOccupied(temporaryCopy[j].X,temporaryCopy[j].Y) == true)
{
mySquares[j].X = temporaryCopy[j].X;
mySquares[j].Y = temporaryCopy[j].Y;
}
}
return canGoDown;
}
//end of moveDown
私のゲームボード クラスには、TCell が占有されているかどうかをチェックするメソッドがあります。TGameBoar は、色と bool isOccupied = false を持つ TCells の配列を保持します。
bool TGameBoard::isCellOccupied(int c,int r)
{
//Checks if TCell is occupied
return myGrid[c,r]->getIsOccupied();
}
それはクラッシュし、ここに問題があることを示しています.Imは現在学校でC ++を学んでいます。助けていただければ幸いです。また、e->KeyData == Keys::Left) などを使用して左右に移動し、ループを通過したときに新しいブロックを作成するための Keydown にも苦労しています。あなたがそれをチェックしたいなら、私は私のプロジェクトrarを持っています。私はすべてのクラスを完了しましたが、それをまとめるだけでも大変です。