diff --git a/knockoutwhistweb/app/controllers/IngameController.scala b/knockoutwhistweb/app/controllers/IngameController.scala index 59749c3..c70aede 100644 --- a/knockoutwhistweb/app/controllers/IngameController.scala +++ b/knockoutwhistweb/app/controllers/IngameController.scala @@ -8,6 +8,7 @@ import model.sessions.{PlayerSession, UserSession} import play.api.* import play.api.mvc.* +import java.util.UUID import javax.inject.* import scala.util.Try @@ -28,7 +29,7 @@ class IngameController @Inject()( game match { case Some(g) => g.logic.getCurrentState match { - case Lobby => Ok("Lobby: " + gameId) + case Lobby => Ok(views.html.lobby.lobby(Some(request.user), g)) case InGame => Ok(views.html.ingame.ingame( g.getPlayerByUser(request.user), @@ -63,7 +64,7 @@ class IngameController @Inject()( } } if (result.isSuccess) { - NoContent + Redirect(routes.IngameController.game(gameId)) } else { val throwable = result.failed.get throwable match { @@ -78,6 +79,16 @@ class IngameController @Inject()( } } } + def kickPlayer(gameId: String, playerToKick: UUID): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => + val game = podManager.getGame(gameId) + game.get.leaveGame(playerToKick) + Redirect(routes.IngameController.game(gameId)) + } + def leaveGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => + val game = podManager.getGame(gameId) + game.get.leaveGame(request.user.id) + Redirect(routes.MainMenuController.mainMenu()) + } def joinGame(gameId: String): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => val game = podManager.getGame(gameId) val result = Try { diff --git a/knockoutwhistweb/app/controllers/MainMenuController.scala b/knockoutwhistweb/app/controllers/MainMenuController.scala index 7032b52..60b0081 100644 --- a/knockoutwhistweb/app/controllers/MainMenuController.scala +++ b/knockoutwhistweb/app/controllers/MainMenuController.scala @@ -21,7 +21,7 @@ class MainMenuController @Inject()( // Pass the request-handling function directly to authAction (no nested Action) def mainMenu(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => - Ok(views.html.mainmenu.navbar(Some(request.user))) + Ok(views.html.mainmenu.creategame(Some(request.user))) } def index(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => @@ -29,12 +29,20 @@ class MainMenuController @Inject()( } def createGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => - val gameLobby = podManager.createGame( - host = request.user, - name = s"${request.user.name}'s Game", - maxPlayers = 4 - ) - Redirect(routes.IngameController.game(gameLobby.id)) + val postData = request.body.asFormUrlEncoded + if (postData.isDefined) { + val gamename = postData.get.get("lobbyname").flatMap(_.headOption).getOrElse(s"${request.user.name}'s Game") + val playeramount = postData.get.get("playeramount").flatMap(_.headOption).getOrElse("") + val gameLobby = podManager.createGame( + host = request.user, + name = gamename, + maxPlayers = playeramount.toInt + ) + Redirect(routes.IngameController.game(gameLobby.id)) + } else { + BadRequest("Invalid form submission") + } + } def joinGame(): Action[AnyContent] = authAction { implicit request: AuthenticatedRequest[AnyContent] => diff --git a/knockoutwhistweb/app/logic/game/GameLobby.scala b/knockoutwhistweb/app/logic/game/GameLobby.scala index 6743bdb..eedbd58 100644 --- a/knockoutwhistweb/app/logic/game/GameLobby.scala +++ b/knockoutwhistweb/app/logic/game/GameLobby.scala @@ -88,12 +88,12 @@ class GameLobby private( * Remove the user from the game lobby. * @param user the user who wants to leave the game. */ - def leaveGame(user: User): Unit = { - val sessionOpt = users.get(user.id) + def leaveGame(userId: UUID): Unit = { + val sessionOpt = users.get(userId) if (sessionOpt.isEmpty) { throw new NotInThisGameException("You are not in this game!") } - users.remove(user.id) + users.remove(userId) } /** @@ -176,6 +176,10 @@ class GameLobby private( getPlayerBySession(getUserSession(user.id)) } + def getPlayers: mutable.Map[UUID, UserSession] = { + users.clone() + } + private def getPlayerBySession(userSession: UserSession): AbstractPlayer = { val playerOption = getMatch.totalplayers.find(_.id == userSession.id) if (playerOption.isEmpty) { @@ -225,7 +229,7 @@ class GameLobby private( } trickOpt.get } - + } object GameLobby { diff --git a/knockoutwhistweb/app/views/lobby/lobby.scala.html b/knockoutwhistweb/app/views/lobby/lobby.scala.html new file mode 100644 index 0000000..090b1a7 --- /dev/null +++ b/knockoutwhistweb/app/views/lobby/lobby.scala.html @@ -0,0 +1,84 @@ +@(user: Option[model.users.User], gamelobby: logic.game.GameLobby) + +@main("Lobby") { +
Your text could be here!
+ Remove + } else { +Your text could be here!
+ + } +Your text could be here!
+ } else { +Your text could be here!
+ } +Waiting for the host to start the game...
+