From 28848358dd942d690ea546c06f6146a8b88c180d Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Mon, 7 Mar 2011 00:31:18 +0000 Subject: [PATCH] fixed: if a piece failed to rotate the bucket rotated nonetheless --- games/tetris/tetris_main.c | 13 ++++++++----- games/tetris/variant_fp.c | 27 +++++++++++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/games/tetris/tetris_main.c b/games/tetris/tetris_main.c index fa0220d..0d94ee9 100644 --- a/games/tetris/tetris_main.c +++ b/games/tetris/tetris_main.c @@ -83,6 +83,9 @@ void tetris_main(tetris_variant_t const *const pVariantMethods) tetris_view_setViewMode(pView, TETRIS_VIMO_RUNNING); } + // helper variable which tells us whether the last move was possible + uint8_t bMoveOk = 1; + // what we do depends on what the input module tells us switch (inCmd) { @@ -109,22 +112,22 @@ void tetris_main(tetris_variant_t const *const pVariantMethods) // player shifted the piece to the left case TETRIS_INCMD_LEFT: - tetris_bucket_movePiece(pBucket, TETRIS_BUD_LEFT); + bMoveOk = tetris_bucket_movePiece(pBucket, TETRIS_BUD_LEFT); break; // player shifted the piece to the right case TETRIS_INCMD_RIGHT: - tetris_bucket_movePiece(pBucket, TETRIS_BUD_RIGHT); + bMoveOk = tetris_bucket_movePiece(pBucket, TETRIS_BUD_RIGHT); break; // player rotated the piece clockwise case TETRIS_INCMD_ROT_CW: - tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CW); + bMoveOk = tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CW); break; // player rotated the piece counter clockwise case TETRIS_INCMD_ROT_CCW: - tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CCW); + bMoveOk = tetris_bucket_rotatePiece(pBucket, TETRIS_PC_ROT_CCW); break; // the player decided to make an immediate drop @@ -150,7 +153,7 @@ void tetris_main(tetris_variant_t const *const pVariantMethods) } // inform variant object about the user's last move - pVariantMethods->setLastInput(pVariantData, inCmd); + pVariantMethods->setLastInput(pVariantData, inCmd, bMoveOk); // inform the input module about the requested bearing of the // variant object diff --git a/games/tetris/variant_fp.c b/games/tetris/variant_fp.c index 6816ac3..f1818a0 100644 --- a/games/tetris/variant_fp.c +++ b/games/tetris/variant_fp.c @@ -73,21 +73,32 @@ tetris_highscore_index_t tetris_fp_getHighscoreIndex(void *pVariantData) return TETRIS_HISCORE_FP; } - +/** + * change bearing depending on player's last input + * @param pVariantData the variant data object we want to modify + * @param inCmd the last issued command + * @param bMoveOk 1 if the last move was possible, otherwise 0 + */ void tetris_fp_setLastInput(void *pVariantData, - tetris_input_command_t inCmd) + tetris_input_command_t inCmd, + uint8_t bMoveOk) { assert (pVariantData != NULL); tetris_standard_variant_t *pStdVariant = (tetris_standard_variant_t *)pVariantData; - if (inCmd == TETRIS_INCMD_ROT_CW) + if (bMoveOk) { - pStdVariant->nBearing += 1; - } - else if (inCmd == TETRIS_INCMD_ROT_CCW) - { - pStdVariant->nBearing += 3; + if (inCmd == TETRIS_INCMD_ROT_CW) + { + // piece rotated clockwise -> rotate bucket counter-clockwise + pStdVariant->nBearing += 3; + } + else if (inCmd == TETRIS_INCMD_ROT_CCW) + { + // piece rotated counter-clockwise -> rotate bucket clockwise + pStdVariant->nBearing += 1; + } } pStdVariant->nBearing %= 4; }