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") { +
+
+
+
+
+ Lobby-Name: @gamelobby.name +
+
+ +
+
+
+
+
+
+
Playeramount: @gamelobby.getPlayers.size / @gamelobby.maxPlayers
+
+
+
+ + @if((gamelobby.getUserSession(user.get.id).host)) { + @for(playersession <- gamelobby.getPlayers.values) { +
+
+ Profile +
+ @if(playersession.id == user.get.id) { +
@playersession.name (You)
+

Your text could be here!

+ Remove + } else { +
@playersession.name
+

Your text could be here!

+
+ +
+ } +
+
+
+ } +
+ +
+ } else { + @for(playersession <- gamelobby.getPlayers.values) { +
+
+ Profile +
+ @if(playersession.id == user.get.id) { +
@playersession.name (You)
+

Your text could be here!

+ } else { +
@playersession.name
+

Your text could be here!

+ } +
+
+
+ } +
+
+

Waiting for the host to start the game...

+
+
+
+
+
+
+ Loading... +
+
+
+
+ } +
+
+} \ No newline at end of file diff --git a/knockoutwhistweb/app/views/mainmenu/creategame.scala.html b/knockoutwhistweb/app/views/mainmenu/creategame.scala.html new file mode 100644 index 0000000..47dc09c --- /dev/null +++ b/knockoutwhistweb/app/views/mainmenu/creategame.scala.html @@ -0,0 +1,31 @@ +@(user: Option[model.users.User]) +@navbar(user) +@main("Create Game") { +
+
+
+ + +
+
+ + +
+
+ + +
+ 2 + 3 + 4 + 5 + 6 + 7 +
+
+
+ +
+
+
+} \ No newline at end of file diff --git a/knockoutwhistweb/app/views/mainmenu/navbar.scala.html b/knockoutwhistweb/app/views/mainmenu/navbar.scala.html index a5f9cc4..99d5c83 100644 --- a/knockoutwhistweb/app/views/mainmenu/navbar.scala.html +++ b/knockoutwhistweb/app/views/mainmenu/navbar.scala.html @@ -1,5 +1,4 @@ @(user: Option[model.users.User]) -@main("Knockout Whist - Main Menu") { -} diff --git a/knockoutwhistweb/conf/routes b/knockoutwhistweb/conf/routes index f1867c7..bba5dda 100644 --- a/knockoutwhistweb/conf/routes +++ b/knockoutwhistweb/conf/routes @@ -24,6 +24,7 @@ GET /logout controllers.UserController.logout() # In-game routes GET /game/:id controllers.IngameController.game(id: String) GET /game/:id/join controllers.IngameController.joinGame(id: String) -POST /game/:id/start controllers.IngameController.startGame(id: String) - +GET /game/:id/start controllers.IngameController.startGame(id: String) +POST /game/:id/kickPlayer controllers.IngameController.kickPlayer(id: String, playerId: java.util.UUID) +GET /game/:id/leaveGame controllers.IngameController.leaveGame(id: String) POST /game/:id/playCard controllers.IngameController.playCard(id: String) \ No newline at end of file