public async Task <IActionResult> MovePiece(GameModel htmlModel) { var gameId = HttpContext.Session.GetInt32("game"); GameModel output = await GetGameInfo.GetGame(client, (int)gameId); output.MovePiece = new MovePiece(); output.WhosTurn = counter; output.MovePiece.PlayerId = counter.WhosTurn; output.Player = await GetCurrentPlayer.GetPlayer(client, (int)gameId, counter); output.MovePiece.PieceId = htmlModel.MovePiece.PieceId - 1; output.MovePiece.NumberOfFields = htmlModel.DiceThrow; await GetMovePiece.MovePiece(client, output.MovePiece, (int)gameId); output.PlayerList = await GetPlayerInfo.GetPlayerPosition((int)gameId, output.NumberOfPlayers, client); counter.UpdatePlayerTurn(output.NumberOfPlayers); output.Player = output.PlayerList[counter.WhosTurn]; output.Winner = await GetWinner.GetPlayer(client, (int)gameId); if (output.Winner != null) { Log.Information($"{output.Winner.Name} won the game: {gameId}! (IP: {HttpContext.Connection.RemoteIpAddress.ToString()})"); } ModifyPlayerStartPosition.SetStartPosition(output); return(View("Gameboard", output)); }
public async Task <IActionResult> RollDice() { var gameId = HttpContext.Session.GetInt32("game"); GameModel output = await GetGameInfo.GetGame(client, (int)gameId); output.Player = await GetCurrentPlayer.GetPlayer(client, (int)gameId, counter); output.DiceThrow = await GetDiceThrow.RollDice(client); output.PlayerList = await GetPlayerInfo.GetPlayerPosition((int)gameId, output.NumberOfPlayers, client); ModifyPlayerStartPosition.SetStartPosition(output); return(View("gameboard", output)); }
public async Task <IActionResult> JoinGame(int gameId) { HttpContext.Session.SetInt32("game", gameId); var response = new RestRequest($"api/ludo/{gameId}", Method.GET); var restResponse = await client.ExecuteTaskAsync(response); GameModel output = JsonConvert.DeserializeObject <GameModel>(restResponse.Content); output.WhosTurn = counter; output.Player = await GetCurrentPlayer.GetPlayer(client, gameId, counter); output.PlayerList = await GetPlayerInfo.GetPlayerPosition(gameId, output.NumberOfPlayers, client); return(View("gameboard", output)); }