Merge pull request #116 from lucasnlm/fix-first-open

Open tile on first tap when Double Click or Fast Flag by @sergeiwork
This commit is contained in:
Lucas Nunes 2020-07-01 23:37:58 -03:00 committed by GitHub
commit 417b1af887
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 2 deletions

View file

@ -294,8 +294,13 @@ class GameController {
}
}
ActionResponse.SwitchMark -> {
if (isCovered) switchMark()
1
if (!hasMines) {
plantMinesExcept(id, true)
openTile()
} else if (isCovered) {
switchMark()
1
} else 0
}
ActionResponse.HighlightNeighbors -> {
if (minesAround != 0) highlight() else 0

View file

@ -831,4 +831,28 @@ class GameControllerTest {
}
}
}
@Test
fun testIfDoubleClickPlantMinesOnFirstClick() {
gameControllerOf(9, 9, 72, 200L).run {
updateGameControl(GameControl.fromControlType(ControlStyle.DoubleClick))
assertFalse(hasMines)
assertEquals(0, field.filterNot { it.isCovered }.count())
singleClick(40)
assertTrue(hasMines)
at(40).findNeighbors().forEach { assertFalse(it.isCovered) }
}
}
@Test
fun testIfFastFlagPlantMinesOnFirstClick() {
gameControllerOf(9, 9, 72, 200L).run {
updateGameControl(GameControl.fromControlType(ControlStyle.FastFlag))
assertFalse(hasMines)
assertEquals(0, field.filterNot { it.isCovered }.count())
singleClick(40)
assertTrue(hasMines)
at(40).findNeighbors().forEach { assertFalse(it.isCovered) }
}
}
}