Skip to content

Commit

Permalink
fix(ghost): ghost block overloads current block
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablito2020 committed Apr 23, 2022
1 parent b4a1840 commit aca156e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main/kotlin/game/ghost/GhostGame.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package game.ghost

import block_factory.BlockCreator
import board.Cell
import game.Game
import game.GameCell
import game.normal.NormalGame
Expand Down Expand Up @@ -49,7 +50,8 @@ class GhostGame(creator: BlockCreator, scoreCalculator: ScoreCalculator) : Game
// Write Result
for (position in result) {
val currentGhostBlock = GameCell(grid[position.row][position.column].cell, false, true)
grid[position.row + distance][position.column] = currentGhostBlock
if (grid[position.row + distance][position.column].cell == Cell.EMPTY)
grid[position.row + distance][position.column] = currentGhostBlock
}
return grid
}
Expand Down
23 changes: 21 additions & 2 deletions src/test/kotlin/game/ghost/GameGhostTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import board.Cell
import game.normal.GAME_COLUMNS
import game.normal.GAME_ROWS
import game.GameCell
import movements.Direction
import movements.Position
import movements.Rotation
import org.junit.jupiter.api.Assertions
Expand Down Expand Up @@ -33,7 +34,7 @@ class GameGhostTest {
}

@Test
fun `get grid after first get block, all in same row`() {
fun `get grid after first I block returns top block and down ghost`() {
game.generateNextBlock()
val expectedGrid = MutableList(GAME_ROWS) { MutableList(GAME_COLUMNS) { GameCell(Cell.EMPTY, false) } }
// Actual Grid
Expand All @@ -50,7 +51,7 @@ class GameGhostTest {
}

@Test
fun `get grid after first get block, all in same column`() {
fun `get grid after rotated I block returns rotated I ghost`() {
game.generateNextBlock()
game.rotateBlock(Rotation.LEFT_90_DEGREE)
val expectedGrid = MutableList(GAME_ROWS) { MutableList(GAME_COLUMNS) { GameCell(Cell.EMPTY, false) } }
Expand All @@ -67,4 +68,22 @@ class GameGhostTest {
Assertions.assertEquals(expectedGrid, game.getGrid())
}

@Test
fun `Current block has more priority than ghost block`() {
game.generateNextBlock()
game.rotateBlock(Rotation.LEFT_90_DEGREE)
for (i in 0 until 14)
game.moveBlock(Direction.DOWN)
val expectedGrid = MutableList(GAME_ROWS) { MutableList(GAME_COLUMNS) { GameCell(Cell.EMPTY, false) } }
// Actual Grid
expectedGrid[14][4] = GameCell(Cell.I_BLOCK, true)
expectedGrid[15][4] = GameCell(Cell.I_BLOCK, true)
expectedGrid[16][4] = GameCell(Cell.I_BLOCK, true)
expectedGrid[17][4] = GameCell(Cell.I_BLOCK, true)
// Ghost
expectedGrid[18][4] = GameCell(Cell.I_BLOCK, false, true)
expectedGrid[19][4] = GameCell(Cell.I_BLOCK, false, true)
Assertions.assertEquals(expectedGrid, game.getGrid())
}

}

0 comments on commit aca156e

Please sign in to comment.