public IActionResult GameRefresh([FromBody] GameRefreshData data) { string userID = _signInManager.UserManager.GetUserId(User); bool IsMyTurn = _GameRepo.IsActivePlayer(data.GameID, userID); bool isChecked = false; ChessboardPartialViewModel game = null; var gamestate = _GameRepo.GetGamestate(data.GameID); bool isactive = gamestate.IsActive; if (IsMyTurn) { var changedTiles = _GameRepo.GetChangedTiles(data.GameID); char userColor = _GameRepo.GetPlayerColor(data.GameID, userID); if (userColor == 'w') { isChecked = _chessLogicManager.IsWhiteChecked(gamestate.Board); } else { isChecked = _chessLogicManager.IsBlackChecked(gamestate.Board); } game = new ChessboardPartialViewModel { GameState = gamestate, SelectedTile = null, CanMoveToAndTakeTiles = new List <string>(), CanMoveToTiles = new List <string>(), GameId = data.GameID, PlayerColor = userColor, ChangedTiles = changedTiles.ToList() }; } // Game will be null if not users turn. return(Json(new GameViewData { Game = game, MoveCount = gamestate.MovesCounter, IsActive = isactive, IsMyTurn = IsMyTurn, IsChecked = isChecked })); }
public IActionResult NewGame([FromBody] UserIdDTO id) { var userId = _signInManager.UserManager.GetUserId(User); var opponentId = id.UserID; bool tooManyGames = _GameRepo.GetAllGames(userId).Where(p => p.OpponentName.Equals(_GameRepo.GetUserNameFromId(opponentId))).Count() >= 3; if (tooManyGames) { return(Json(new GameRefreshData { GameID = "" })); } var newGameID = _GameRepo.AddNewGame(_signInManager.UserManager.GetUserId(User), id.UserID); var data = new GameRefreshData { GameID = newGameID }; return(Json(data)); }