From a8b701223d00c52a10630e395689481a251df0ae Mon Sep 17 00:00:00 2001 From: Pablo Fraile Alonso Date: Fri, 29 Apr 2022 10:38:51 +0200 Subject: [PATCH] fix(blockgenerator): fix next block type --- src/main/kotlin/block_factory/RandomBlockCreator.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/block_factory/RandomBlockCreator.kt b/src/main/kotlin/block_factory/RandomBlockCreator.kt index 2ade87a..2cdd0bf 100644 --- a/src/main/kotlin/block_factory/RandomBlockCreator.kt +++ b/src/main/kotlin/block_factory/RandomBlockCreator.kt @@ -12,17 +12,15 @@ internal const val INITIAL_COLUMN_BLOCK = (GAME_COLUMNS / 2) - 2 class RandomBlockCreator : BlockCreator { - private var actualBlock: BlockWrapper = getNewBlock() - private var nextBlock: BlockWrapper = getNewBlock() + private var block: BlockWrapper = getNewBlock() override fun getBlock(): Block { - val result = actualBlock.block - actualBlock = nextBlock - nextBlock = getNewBlock() + val result = block.block + block = getNewBlock() return result } - override fun getNextBlockType() = nextBlock.type + override fun getNextBlockType() = block.type private fun getNewBlock() = when (val type = BlockType.values().random()) { BlockType.I_BLOCK -> BlockWrapper(IBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), type)