/// <summary> /// Compute next state of the world. Complete game logic for one step. /// </summary> public void Step(TetrisWorld.ActionInputType input) { IsMerging = false; if (m_shouldSpawnTetromino) { m_shouldSpawnTetromino = false; if(!SpawnTetromino()) { // game over ResetLost(); return; } } bool isDrop = false; if (m_stepsFromLastDrop >= GetWaitStepsPerDrop()) { isDrop = true; } switch(input) { case TetrisWorld.ActionInputType.MoveDown: { isDrop = true; break; } case TetrisWorld.ActionInputType.MoveLeft: { m_tetromino.TryMoveLeft(); break; } case TetrisWorld.ActionInputType.MoveRight: { m_tetromino.TryMoveRight(); break; } case TetrisWorld.ActionInputType.RotateLeft: { m_tetromino.TryRotateLeft(); break; } case TetrisWorld.ActionInputType.RotateRight: { m_tetromino.TryRotateRight(); break; } default: case TetrisWorld.ActionInputType.NoAction: { break; } } m_scoreDelta = 0; if (isDrop) { m_stepsFromLastDrop = 0; if(!m_tetromino.TryMoveDown()) { IsMerging = true; CalculateMerge(); m_gameBoard.MergeTetrominoWithGameBoard(m_tetromino); int erasedLines = m_gameBoard.EraseFullLines(); // most often returns 0 m_scoreDelta = 100 * erasedLines * erasedLines; m_score += m_scoreDelta; m_totalErasedLines += erasedLines; m_level = m_totalErasedLines / Math.Max(1,m_params.ClearedLinesPerLevel); m_tetromino = null; m_shouldSpawnTetromino = true; } } else { m_stepsFromLastDrop++; } FillWorldState(); }
public TetrisWorldEngine(TetrisWorld world, WorldEngineParams pars) { m_params = pars; m_world = world; m_rndGen = new Random(); }