Пример #1
0
        public MoveResponseModel AttemptMove(MoveRequestModel request)
        {
            if (!gameplayStateModel.IsPlaying)
            {
                return(new MoveResponseModel()
                {
                    Request = request,
                    ValidMove = false,
                    GameStatus = GameplayStatus.Error,
                    Message = "Game not actively running, cannot process request.",
                    KeyMatches = 0,
                });
            }

            bool invalidKey = gameplayStateModel.ConsumedCharacters.Contains(request.Key);

            if (invalidKey)
            {
                return(new MoveResponseModel()
                {
                    Request = request,
                    ValidMove = false,
                    GameStatus = GameplayStatus.Error,
                    Message = "Repeated Keypress Request, move rejected.",
                    KeyMatches = 0,
                });
            }

            GameplayStatus postMoveStatus = GameplayStatus.Playing;


            int count = 0;
            int index = 0;

            foreach (char c in gameplayStateModel.CurrentWord)
            {
                if (c == request.Key)
                {
                    count++;
                    gameplayStateModel.CurrentWordStatus[index] = c;
                }

                index++;
            }
            gameplayStateModel.GuessedCharacterCount += count;

            bool wasGoodMove = count > 0;

            if (!wasGoodMove)
            {
                gameplayStateModel.ErrorCount++;
            }

            if (gameplayStateModel.GuessedCharacterCount == gameplayStateModel.CurrentWord.Length)
            {
                postMoveStatus = GameplayStatus.Won;
                gameplayStateModel.IsPlaying = false;
                gameplayStateModel.WinCount++;
            }
            else if (postMoveStatus != GameplayStatus.Won && gameplayStateModel.ErrorCount >= gameRulesData.WrongMovesForDeath)
            {
                postMoveStatus = GameplayStatus.Lost;
                gameplayStateModel.IsPlaying = false;
                gameplayStateModel.LossCount++;
            }

            gameplayStateModel.ConsumedCharacters.Add(request.Key);
            return(new MoveResponseModel()
            {
                Request = request,
                ValidMove = true,
                GameStatus = postMoveStatus,
                Message = $"Good Request. {count} matches",
                KeyMatches = count,
            });
        }
Пример #2
0
 public MoveResponseModel RequestMoveAttempt(MoveRequestModel request)
 {
     return(gameSessionService.AttemptMove(request));
 }