Skip to content

Commit

Permalink
fix(blockgenerator): fix next block type
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 29, 2022
1 parent 8fe5527 commit a8b7012
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/main/kotlin/block_factory/RandomBlockCreator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a8b7012

Please sign in to comment.