Exemple #1
0
        private AliceResponse Repeat(AliceRequest request)
        {
            var phrase = new Phrase(
                GameplayService.ReadWord(request.State.Session, _soundEngine, ReadMode.Repeat),
                _ingameButtons
                );

            return(phrase.Generate(request));
        }
Exemple #2
0
        private AliceResponse SetUpGame(AliceRequest request)
        {
            Phrase        phrase;
            List <string> names = request.Request.Nlu.Tokens.Except(new [] { "и" }).ToList();

            if (request.HasIntent("only_me"))
            {
                names = new List <string> {
                    "я"
                }
            }
            ;

            if (names.Count == 0)
            {
                phrase = new Phrase(
                    "Назови подряд имена всех игроков, либо скажи, что играть будешь только ты.",
                    _prepareButtons
                    );
                return(phrase.Generate(request));
            }
            else if (names.Count > 10)
            {
                phrase = new Phrase(
                    "Пока что играть могу не более десяти человек на одном устройстве. Перечисли не более десяти имён.",
                    _prepareButtons
                    );
                return(phrase.Generate(request));
            }

            SessionState state = request.State.Session;

            _gameplayService.Start(request.State.User, state, names.ToArray());

            // read first word
            string playersNum  = names.Count.ToPhrase("игрок", "игрока", "игроков");
            string startPhrase = $"Отлично, {playersNum}, начинаем. " +
                                 $"\n\n{GameplayService.ReadWord(state, _soundEngine, ReadMode.First)}";

            return(new Phrase(startPhrase, _ingameButtons).Generate(request));
        }
    }
Exemple #3
0
        private AliceResponse Hint(AliceRequest request, string prefix = "")
        {
            SessionState state = request.State.Session;

            _gameplayService.HintTaken(state);

            if (request.State.Session.Step == SessionStep.Game)
            {
                var phrase = new Phrase(
                    $"{prefix}Подскажу:\n" +
                    $"{state.CurrentWord.Definition.ToUpperFirst()}.\n" +
                    GameplayService.ReadHint(request.State.Session, _soundEngine),
                    _ingameButtons
                    );

                return(phrase.Generate(request));
            }

            return(Help(request));
        }
Exemple #4
0
        private AliceResponse Score(AliceRequest request)
        {
            Phrase       phrase;
            SessionState state = request.State.Session;

            if (request.State.Session.Step == SessionStep.Game)
            {
                phrase = new Phrase(
                    GameplayService.ReadScoreOnDemand(state, false) +
                    GameplayService.ReadWordsLeft(state) +
                    GameplayService.ReadWord(request.State.Session, _soundEngine, ReadMode.Repeat, true),
                    _ingameButtons
                    );
            }
            else
            {
                return(Repeat(request));
            }

            return(phrase.Generate(request));
        }
Exemple #5
0
        private AliceResponse MaybeRestart(AliceRequest request)
        {
            if (request.HasIntent("yes"))
            {
                return(Enter(request, restart: true));
            }

            // continue game or exit
            SessionState state = request.State.Session;

            if (state.CurrentWord != null)
            {
                _gameplayService.Resume(state);
                return(new Phrase(
                           GameplayService.ReadWord(state, _soundEngine, ReadMode.Continue),
                           _ingameButtons
                           )
                       .Generate(request));
            }

            // exit game
            return(Exit(request));
        }
Exemple #6
0
 public AliceService(GameplayService gameplayService)
 {
     _gameplayService = gameplayService;
 }
Exemple #7
0
        private AliceResponse Answer(AliceRequest request)
        {
            SessionState state    = request.State.Session;
            string       word     = state.CurrentWord.Word;
            string       wordSaid = string.Join("", request.Request.Nlu.Tokens);
            AnswerResult result   = _gameplayService.Answer(request.State.User, request.State.Session, wordSaid);
            string       sound    = result == AnswerResult.Right
                ? "[audio|dialogs-upload/008dafcd-99bc-4fd1-9561-4686c375eec6/7fbd83e1-7c22-468d-a8fe-8f0439000fd6.opus]"
                : "[audio|dialogs-upload/008dafcd-99bc-4fd1-9561-4686c375eec6/ac858f28-3c34-403c-81c7-5d64449e4ea7.opus]";

            string prefix = sound;

            if (result == AnswerResult.SeccondAttempt)
            {
                return(Hint(request, prefix));
            }

            if (result == AnswerResult.Wrong)
            {
                prefix += request.HasScreen()
                    ? $"Правильный ответ: {word.ToUpper()}.\n\n[p|300]"
                    : $"Твой ответ: {wordSaid.ToUpper()}, а правильный: {word.ToUpper()}.\n\n[p|300]";
            }

            var phrase = new Phrase(prefix);

            if (state.CurrentWord == null)
            {
                // game finished
                phrase += new Phrase(
                    "[audio|alice-sounds-game-win-3.opus]Игра завершена!\n" +
                    $"{GameplayService.ReadScore(request.State.User, state)}\n\nХочешь начать новую игру?",
                    _yesNoButtons
                    );
                return(phrase.Generate(request));
            }

            // continue game
            if (state.NeedShowScore())
            {
                _gameplayService.SetScoreShown(state);

                // continue game read score
                phrase += new Phrase(
                    GameplayService.ReadScoreOnDemand(state, state.LeftShown),
                    _ingameButtons
                    );

                // read left words
                if (!state.LeftShown)
                {
                    _gameplayService.SetLeftShown(state);
                    phrase += new Phrase(GameplayService.ReadWordsLeft(state));
                }

                // read word
                phrase += new Phrase(GameplayService.ReadWord(request.State.Session, _soundEngine, ReadMode.Normal, true));
            }
            else
            {
                // just continue game
                phrase += new Phrase(
                    GameplayService.ReadWord(request.State.Session, _soundEngine),
                    _ingameButtons
                    );
            }

            return(phrase.Generate(request));
        }