Esempio n. 1
0
        public async Task <GameBoardState> ResetGameAsync(ResetGameRequest request)
        {
            await Task.Delay(500).ConfigureAwait(false);

            string    userId      = ExtractUserId();
            GameState gameState   = null;
            bool      gameExists  = serverState.Exists(request.GameId);
            bool      validUserId = false;

            if (gameExists)
            {
                gameState   = serverState.GetGameState(request.GameId);
                validUserId = gameState.Player1.Id == userId || gameState.Player2.Id == userId;
            }
            if (!gameExists || !validUserId)
            {
                throw new ArgumentException($"Game with id {request.GameId} not found");
            }

            if (!GameLogicUtils.GameCanBeReset(gameState))
            {
                throw new ArgumentException("Game cannot be reset, only games vs computer and finished games can be reset");
            }

            gameState.BoardState = GameLogicUtils.InitializeGameBoard(request.UserTurn);
            //return Task.FromResult(gameState.BoardState);
            return(gameState.BoardState);
        }
Esempio n. 2
0
        public async Task ResetGame(ResetGameRequest resetGameRequest)
        {
            var gamesPlaysForThisGame = _gamePlays.Where(gp => gp.Game.Id == resetGameRequest.Game.Id).ToList();

            gamesPlaysForThisGame.ForEach(gp => gp.CardPlayed = new Card());

            await UpdateGame(resetGameRequest.Game.Id);
        }