-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(block-creator): add simple and all block queue creator
- Loading branch information
1 parent
e5f17fd
commit fe7068e
Showing
5 changed files
with
94 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package block_factory | ||
|
||
import blocks.implementation.* | ||
import movements.Position | ||
import java.util.* | ||
|
||
class BlockQueueCreator : TemplateQueueCreator(){ | ||
|
||
internal val allBlockQueue: Queue<BlockWrapper> = LinkedList() | ||
|
||
init { | ||
allBlockQueue.addAll( | ||
listOf( | ||
BlockWrapper(IBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.I_BLOCK), | ||
BlockWrapper(JBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.J_BLOCK), | ||
BlockWrapper(SBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.S_BLOCK), | ||
BlockWrapper(ZBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.Z_BLOCK), | ||
BlockWrapper(LBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.L_BLOCK), | ||
BlockWrapper(SquareBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.SQUARE_BLOCK), | ||
BlockWrapper(TBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.T_BLOCK) | ||
) | ||
) | ||
} | ||
|
||
override fun getQueue(): Queue<BlockWrapper> = allBlockQueue | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package block_factory | ||
|
||
import blocks.implementation.* | ||
import movements.Position | ||
import java.util.* | ||
|
||
class SimpleBlockQueueCreator: TemplateQueueCreator() { | ||
|
||
internal val allBlockQueue: Queue<BlockWrapper> = LinkedList() | ||
|
||
init { | ||
allBlockQueue.addAll( | ||
listOf( | ||
BlockWrapper(IBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.I_BLOCK), | ||
BlockWrapper(JBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.J_BLOCK), | ||
BlockWrapper(LBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.L_BLOCK), | ||
BlockWrapper(SquareBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.SQUARE_BLOCK), | ||
BlockWrapper(TBlock(Position(INITIAL_ROW_BLOCK, INITIAL_COLUMN_BLOCK)), BlockType.T_BLOCK) | ||
) | ||
) | ||
} | ||
|
||
override fun getQueue(): Queue<BlockWrapper> = allBlockQueue | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package block_factory | ||
|
||
import blocks.Block | ||
import game.normal.GAME_COLUMNS | ||
|
||
internal data class BlockWrapper(val block: Block, val type: BlockType) | ||
|
||
internal const val INITIAL_ROW_BLOCK = 0 | ||
internal const val INITIAL_COLUMN_BLOCK = (GAME_COLUMNS / 2) - 2 | ||
|
||
abstract class TemplateBlockCreator : BlockCreator { | ||
|
||
private var block: BlockWrapper = getNewBlock() | ||
|
||
override fun getBlock(): Block { | ||
val result = block.block | ||
block = getNewBlock() | ||
return result | ||
} | ||
|
||
override fun getNextBlockType() = block.type | ||
|
||
internal abstract fun getNewBlock(): BlockWrapper | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package block_factory | ||
|
||
import java.util.* | ||
|
||
abstract class TemplateQueueCreator: TemplateBlockCreator() { | ||
|
||
override fun getNewBlock(): BlockWrapper { | ||
val queue = getQueue() | ||
val element = queue.poll() | ||
queue.add(element.copy()) | ||
return element | ||
} | ||
|
||
internal abstract fun getQueue(): Queue<BlockWrapper> | ||
|
||
} |