34 lines
911 B
Kotlin
34 lines
911 B
Kotlin
class GameLoop(private val first: Character,
|
|
private val second: Character,
|
|
val complition: (Character, Character) -> Unit) {
|
|
|
|
fun init() {
|
|
//enemy must be initialize first since the Card initiate needs them
|
|
first.enemy = second
|
|
second.enemy = first
|
|
first.endGameAsLoser = { //first's deck is dry
|
|
complition(second, first)
|
|
}
|
|
second.endGameAsLoser = { //second's deck is dry
|
|
complition(first, second)
|
|
}
|
|
first.drawFromDeck(3)
|
|
second.drawFromDeck(3)
|
|
}
|
|
|
|
fun start() {
|
|
while(first.life > 0 && second.life > 0) {
|
|
first.nextTurn()
|
|
second.nextTurn()
|
|
}
|
|
endGame()
|
|
}
|
|
|
|
|
|
|
|
private fun endGame() {
|
|
val winner = if (first.life > 0) first else second
|
|
val loser = winner.enemy
|
|
complition(winner, loser)
|
|
}
|
|
} |