summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-02-22 23:09:40 +0100
committerjbion <joffrey.bion@amadeus.com>2019-02-22 23:09:40 +0100
commit27990fcba5a47252df617db1bc98e2276b326e7e (patch)
tree7fba886ae83379ee9d76e6540efae7b0e7ce2a25 /backend
parentFix websocket value when no message body is received (diff)
downloadseven-wonders-27990fcba5a47252df617db1bc98e2276b326e7e.tar.gz
seven-wonders-27990fcba5a47252df617db1bc98e2276b326e7e.tar.bz2
seven-wonders-27990fcba5a47252df617db1bc98e2276b326e7e.zip
Implement Game start
Diffstat (limited to 'backend')
-rw-r--r--backend/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt16
-rw-r--r--backend/src/main/kotlin/org/luxons/sevenwonders/controllers/HomeController.kt6
-rw-r--r--backend/src/main/kotlin/org/luxons/sevenwonders/output/PreparedCard.kt6
3 files changed, 12 insertions, 16 deletions
diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt
index e05bf319..0cee6531 100644
--- a/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt
+++ b/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/GameController.kt
@@ -2,10 +2,12 @@ package org.luxons.sevenwonders.controllers
import org.hildan.livedoc.core.annotations.Api
import org.luxons.sevenwonders.actions.PrepareMoveAction
+import org.luxons.sevenwonders.api.PlayerDTO
+import org.luxons.sevenwonders.api.toDTO
import org.luxons.sevenwonders.game.Game
import org.luxons.sevenwonders.game.api.Table
+import org.luxons.sevenwonders.game.cards.CardBack
import org.luxons.sevenwonders.lobby.Player
-import org.luxons.sevenwonders.output.PreparedCard
import org.luxons.sevenwonders.repositories.PlayerRepository
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
@@ -42,13 +44,13 @@ class GameController @Autowired constructor(
val lobby = player.lobby
val players = lobby.getPlayers()
- val allReady = players.stream().allMatch { it.isReady }
+ sendPlayerReady(game.id, player)
+
+ val allReady = players.all { it.isReady }
if (allReady) {
logger.info("Game {}: all players ready, sending turn info", game.id)
players.forEach { it.isReady = false }
sendTurnInfo(players, game)
- } else {
- sendPlayerReady(game.id, player)
}
}
@@ -60,7 +62,7 @@ class GameController @Autowired constructor(
}
private fun sendPlayerReady(gameId: Long, player: Player) =
- template.convertAndSend("/topic/game/$gameId/playerReady", player.username)
+ template.convertAndSend("/topic/game/$gameId/playerReady", "\"${player.username}\"")
/**
* Prepares the player's next move. When all players have prepared their moves, all moves are executed.
@@ -75,7 +77,7 @@ class GameController @Autowired constructor(
val player = principal.player
val game = player.game
val preparedCardBack = game.prepareMove(player.index, action.move)
- val preparedCard = PreparedCard(player, preparedCardBack)
+ val preparedCard = PreparedCard(player.toDTO(principal.name), preparedCardBack)
logger.info("Game {}: player {} prepared move {}", game.id, principal.name, action.move)
if (game.allPlayersPreparedTheirMove()) {
@@ -97,3 +99,5 @@ class GameController @Autowired constructor(
private val logger = LoggerFactory.getLogger(GameController::class.java)
}
}
+
+class PreparedCard(val player: PlayerDTO, val cardBack: CardBack)
diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/HomeController.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/HomeController.kt
index a3ccd148..bd672000 100644
--- a/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/HomeController.kt
+++ b/backend/src/main/kotlin/org/luxons/sevenwonders/controllers/HomeController.kt
@@ -25,10 +25,8 @@ class HomeController @Autowired constructor(
/**
* Creates/updates the player's name (for the user's session).
*
- * @param action
- * the action to choose the name of the player
- * @param principal
- * the connected user's information
+ * @param action the action to choose the name of the player
+ * @param principal the connected user's information
*
* @return the created [PlayerDTO] object
*/
diff --git a/backend/src/main/kotlin/org/luxons/sevenwonders/output/PreparedCard.kt b/backend/src/main/kotlin/org/luxons/sevenwonders/output/PreparedCard.kt
deleted file mode 100644
index 956b1a2c..00000000
--- a/backend/src/main/kotlin/org/luxons/sevenwonders/output/PreparedCard.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package org.luxons.sevenwonders.output
-
-import org.luxons.sevenwonders.game.cards.CardBack
-import org.luxons.sevenwonders.lobby.Player
-
-class PreparedCard(val player: Player, val cardBack: CardBack)
bgstack15