Ejemplo n.º 1
0
        public async Task <GameState> Handle(Guid tableId, GuessCommand command)
        {
            Task <GameState> loadStateTask = _reader.LoadTableState(tableId);

            await loadStateTask;

            GameState currentState = loadStateTask.Result;
            GameState newState     = CommandsHandler.Handle(currentState, command);

            await _writer.WriteGameState(newState);

            return(newState);
        }
Ejemplo n.º 2
0
 public ActionResult <GameState> Guess(string tableId, [FromBody] GuessCommand guessCommand)
 {
     return(_commandFacade.Handle(Guid.Parse(tableId), guessCommand).Result);
 }
        /// <summary>
        /// Checks if the user input is correct and creates corresponding command
        /// </summary>
        /// <param name="command">User input command</param>
        /// <returns>The created command</returns>
        private ICommand ProcessGuessAndReturnAppropriateCommand(string command)
        {
            ICommand commandExecutor = null;

            if (this.FourDigitNumberPattern.IsMatch(command) && (command.Length == 4))
            {
                if (this.Data.GuessAttempts <= this.Data.GuessAttemptsMaxValue)
                {
                    if (command.Equals(this.Data.NumberToGuess))
                    {
                        commandExecutor = new WinGameCommand(this.Notifier, this.Scoreboard, this.Data);
                    }
                    else
                    {
                        commandExecutor = new GuessCommand(this.Data, this.Notifier, command);
                    }
                }
                else
                {
                    commandExecutor = new DisplayMessageCommand(this.Notifier, false, MaxGuessesLimitMessage);
                }
            }
            else
            {
                commandExecutor = new DisplayMessageCommand(this.Notifier, true, InputWarningMessage);
            }

            return commandExecutor;
        }