diff options
author | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-03 02:37:38 +0100 |
---|---|---|
committer | joffrey-bion <joffrey.bion@gmail.com> | 2021-02-03 23:29:16 +0100 |
commit | 7c2371766b940742f3986d7904d4c20a4127ea70 (patch) | |
tree | 294d0c80b2590b69d032a37bcc78b3ce15be012a /sw-client/src | |
parent | Cleanup (diff) | |
download | seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.tar.gz seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.tar.bz2 seven-wonders-7c2371766b940742f3986d7904d4c20a4127ea70.zip |
Add auto-game with bots only
Resolves:
https://github.com/joffrey-bion/seven-wonders/issues/82
Diffstat (limited to 'sw-client/src')
-rw-r--r-- | sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt index 68026888..fc097d86 100644 --- a/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt +++ b/sw-client/src/commonMain/kotlin/org/luxons/sevenwonders/client/SevenWondersClient.kt @@ -1,5 +1,7 @@ package org.luxons.sevenwonders.client +import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map @@ -148,8 +150,30 @@ class SevenWondersSession(private val stompSession: StompSessionWithKxSerializat } } -suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO { - val joinedLobbies = watchLobbyJoined() +suspend fun SevenWondersSession.createGameAndWaitLobby(gameName: String): LobbyDTO = coroutineScope { + val lobbies = watchLobbyJoined() + val joinedLobby = async { lobbies.first() } + createGame(gameName) + joinedLobby.await() +} + +suspend fun SevenWondersSession.joinGameAndWaitLobby(gameId: Long): LobbyDTO = coroutineScope { + val lobbies = watchLobbyJoined() + val joinedLobby = async { lobbies.first() } + joinGame(gameId) + joinedLobby.await() +} + +suspend fun SevenWondersSession.startGameAndAwaitFirstTurn(): PlayerTurnInfo = coroutineScope { + val gameStartedEvents = watchGameStarted() + val deferredFirstTurn = async { gameStartedEvents.first() } + startGame() + deferredFirstTurn.await() +} + +suspend fun SevenWondersSession.joinGameAndWaitFirstTurn(gameId: Long): PlayerTurnInfo = coroutineScope { + val gameStartedEvents = watchGameStarted() + val deferredFirstTurn = async { gameStartedEvents.first() } joinGame(gameId) - return joinedLobbies.first() + deferredFirstTurn.await() } |