Skip to content

Commit

Permalink
Merge pull request #87 from EntelectChallenge/feature/current-worm-dead
Browse files Browse the repository at this point in the history
Feature/current worm dead
  • Loading branch information
Blaarkies committed Sep 2, 2019
2 parents fa45a5c + f7304a8 commit 2ec1269
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion game-engine/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "za.co.entelect.challenge"
version = "2019.3.1"
version = "2019.3.2"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class WormsPlayer private constructor(val id: Int,
//Assign living worms to a local variable since it is a computed property
val livingWorms = this.livingWorms
if (livingWorms.isNotEmpty()) {
val nextIndex = (livingWorms.indexOf(currentWorm) + 1) % livingWorms.size
updateCurrentWorm(livingWorms[nextIndex])
val nextWorm = livingWorms.firstOrNull { it.id > currentWorm.id } ?: livingWorms.first()
updateCurrentWorm(nextWorm)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,46 @@ class WormsPlayerTest {
assertEquals(player.worms[0], player.currentWorm)
}

@Test
fun test_player_wormSelection_All() {
val player = WormsPlayer.build(2, config)
assertEquals(1, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[1], player.currentWorm)
assertEquals(2, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[2], player.currentWorm)
assertEquals(3, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[0], player.currentWorm)
assertEquals(1, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[1], player.currentWorm)
assertEquals(2, player.currentWorm.id)

player.selectNextWorm()
assertEquals(player.worms[2], player.currentWorm)
assertEquals(3, player.currentWorm.id)
}

@Test
fun test_player_wormSelection_currentWormDead() {
val player = WormsPlayer.build(2, config)

player.updateCurrentWorm(player.worms[1])
player.worms[1].health = 0;

assertEquals(2, player.currentWorm.id);

player.selectNextWorm();

assertEquals(3, player.currentWorm.id)
}

@Test
fun test_player_dead() {
val player = WormsPlayer.build(0, config)
Expand Down

0 comments on commit 2ec1269

Please sign in to comment.