示例#1
0
        private async void SecondRoundReceivingAnswers(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();

            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                var time     = DateTime.Now.AddSeconds(roundOptions.Value.SecondRoundReceivingAnswersInterval / 1000);
                var question = process.Data.SecondRoundResult.MixedQuestions[process.Data.SecondRoundResult.QuestionIndex];

                process.Data.SecondRoundResult.State = PlayState.ReceivingAnswers;

                await gameProcessService.Save();
                await SendEvent(process.Data, "SecondRoundReceivingAnswers", new ServiceResult <SecondRoundQuestionViewModel>
                {
                    IsSuccess = true,
                    Data      = new SecondRoundQuestionViewModel(time, question)
                });;

                var timer = new Timer
                {
                    Interval  = roundOptions.Value.SecondRoundReceivingAnswersInterval,
                    AutoReset = false
                };
                timer.Elapsed += (sender, e) => SecondRoundSelectQuestion(gameProcessId);
                timer.Start();
            }
        }
示例#2
0
        private async void SecondRoundWaitStart(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();
            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                process.Data.State = GameProcessState.WaitingSecondRound;
                await gameProcessService.Save();
                await SendGameState(process.Data.Id);
            }
        }
示例#3
0
        private async void ThirdRoundBreak(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();
            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                process.Data.State = GameProcessState.ThirdRoundBreak;
                await gameProcessService.Save();
                await SendGameState(process.Data.Id);

                //await SendEvent(process.Data, "SecondRoundWait", new ServiceResult<object>
                //{
                //    IsSuccess = true,
                //    Data = null
                //});
            }
        }
示例#4
0
        private async void FirstRoundShowAd(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();
            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                process.Data.State = GameProcessState.FirstRoundAd;
                await gameProcessService.Save();
                await SendGameState(process.Data.Id);

                var timer = new Timer
                {
                    Interval  = roundOptions.Value.FirstRoundAdInterval,
                    AutoReset = false
                };
                timer.Elapsed += (sender, e) => SecondRoundWaitStart(gameProcessId);
                timer.Start();
            }
        }
示例#5
0
        private async void FirstRoundSelectQuestion(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();
            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                var time = DateTime.Now.AddSeconds(roundOptions.Value.FirstRoundReceivingAnswersInterval / 1000);
                process.Data.FirstRoundResult.QuestionIndex++;
                if (process.Data.FirstRoundResult.QuestionIndex == process.Data.FirstRoundResult.MixedQuestions.Count)
                {
                    FirstRoundShowAd(process.Data.Id);
                    return;
                }
                process.Data.FirstRoundResult.State = PlayState.SelectQuestion;

                await gameProcessService.Save();

                var lastQuestion = process.Data.FirstRoundResult.QuestionIndex == 0 ? null : process.Data.FirstRoundResult.MixedQuestions[process.Data.FirstRoundResult.QuestionIndex - 1]?.Answers?.FirstOrDefault(x => x.Index == 0);
                await SendEvent(process.Data, "FirstRoundSelectQuestion", new ServiceResult <object>
                {
                    IsSuccess = true,
                    Data      = new
                    {
                        Time          = time,
                        CorrectAnswer = lastQuestion != null ? new { lastQuestion.Id, lastQuestion.Value } : null
                    }
                });

                var timer = new Timer
                {
                    Interval  = roundOptions.Value.FirstRoundReceivingAnswersInterval,
                    AutoReset = false
                };
                timer.Elapsed += (sender, e) => FirstRoundReceivingAnswers(process.Data.Id);
                timer.Start();
            }
        }
示例#6
0
        private async void ThirdRoundReceivingAnswers(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();

            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                var time = DateTime.Now.AddSeconds(roundOptions.Value.ThirdRoundReceivingAnswersInterval / 1000);

                process.Data.ThirdRoundResult.State           = PlayState.ReceivingAnswers;
                process.Data.ThirdRoundResult.AnswerCloseTime = time;

                await gameProcessService.Save();

                switch (process.Data.ThirdRoundResult.ThirdRoundState)
                {
                case ThirdRoundState.Chronology:
                    var question = process.Data.Game.ThirdRound.Chronologies[process.Data.ThirdRoundResult.QuestionIndex];
                    await SendEvent(process.Data, "ThirdRoundReceivingAnswers", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State           = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time            = time,
                            ChronologyItems = question.ChronologyItems.Select(x => new
                            {
                                x.File.Path,
                                x.Value,
                                x.Id
                            })
                        }
                    });

                    break;

                case ThirdRoundState.MelodyGuess:
                    var melody = process.Data.Game.ThirdRound.MelodyGuesses[process.Data.ThirdRoundResult.QuestionIndex];
                    await SendEvent(process.Data, "ThirdRoundReceivingAnswers", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State               = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time                = time,
                            FilePath            = melody.File.Path,
                            MelodyGuessVariants = melody.MelodyGuessVariants.Select(x => new
                            {
                                x.Value,
                                x.Id
                            })
                        }
                    });

                    break;

                case ThirdRoundState.Association:
                    var association = process.Data.Game.ThirdRound.Associations[process.Data.ThirdRoundResult.QuestionIndex];
                    await SendEvent(process.Data, "ThirdRoundReceivingAnswers", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time  = time,
                            Word  = association.Word,
                            AssociationVariants = association.AssociationVariants.Select(x => new
                            {
                                x.Value,
                                x.Id
                            })
                        }
                    });

                    break;
                }

                var timer = new Timer
                {
                    Interval  = roundOptions.Value.ThirdRoundReceivingAnswersInterval,
                    AutoReset = false
                };
                timer.Elapsed += (sender, e) => ThirdRoundSelectQuestion(gameProcessId);
                timer.Start();
            }
        }
示例#7
0
        private async void ThirdRoundSelectQuestion(int gameProcessId)
        {
            gameProcessService = serviceScopeFactory.CreateScope().ServiceProvider.GetService <IGameProcessService>();
            dataContext        = serviceScopeFactory.CreateScope().ServiceProvider.GetService <DataContext>();
            var process = gameProcessService.GetGameProcess(gameProcessId);

            if (process.IsSuccess)
            {
                var time = DateTime.Now.AddSeconds(roundOptions.Value.ThirdRoundSelectQuestionInterval / 1000);
                process.Data.ThirdRoundResult.QuestionIndex++;

                switch (process.Data.ThirdRoundResult.ThirdRoundState)
                {
                case ThirdRoundState.Chronology:
                    var lastChronology = process.Data.ThirdRoundResult.QuestionIndex == 0 ? null : process.Data.Game.ThirdRound.Chronologies[process.Data.ThirdRoundResult.QuestionIndex - 1];
                    await SendEvent(process.Data, "ThirdRoundSelectQuestion", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State      = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time       = time,
                            Chronology = lastChronology != null ? new
                            {
                                Items = lastChronology.ChronologyItems.OrderBy(x => x.Index).Select(x => new
                                {
                                    x.File.Path,
                                    x.Value,
                                    x.Index
                                })
                            } : null
                        }
                    });

                    break;

                case ThirdRoundState.MelodyGuess:
                    var lastMelody = process.Data.ThirdRoundResult.QuestionIndex == 0 ? null : process.Data.Game.ThirdRound.MelodyGuesses[process.Data.ThirdRoundResult.QuestionIndex - 1];
                    await SendEvent(process.Data, "ThirdRoundSelectQuestion", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State  = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time   = time,
                            Melody = lastMelody != null ? new
                            {
                                CorrectAnswer = new
                                {
                                    lastMelody.MelodyGuessVariants.FirstOrDefault(x => x.Index == 0).Value,
                                    lastMelody.MelodyGuessVariants.FirstOrDefault(x => x.Index == 0).Id
                                }
                            } : null
                        }
                    });

                    break;

                case ThirdRoundState.Association:
                    var lastAssociation = process.Data.ThirdRoundResult.QuestionIndex == 0 ? null : process.Data.Game.ThirdRound.Associations[process.Data.ThirdRoundResult.QuestionIndex - 1];
                    await SendEvent(process.Data, "ThirdRoundSelectQuestion", new ServiceResult <object>
                    {
                        IsSuccess = true,
                        Data      = new
                        {
                            State       = process.Data.ThirdRoundResult.ThirdRoundState,
                            Time        = time,
                            Association = lastAssociation != null ? new
                            {
                                CorrectAnswer = new
                                {
                                    lastAssociation.AssociationVariants.FirstOrDefault(x => x.Index == 0).Value,
                                    lastAssociation.AssociationVariants.FirstOrDefault(x => x.Index == 0).Id
                                }
                            } : null
                        }
                    });

                    break;
                }

                switch (process.Data.ThirdRoundResult.ThirdRoundState)
                {
                case ThirdRoundState.Chronology:
                    if (process.Data.ThirdRoundResult.QuestionIndex == process.Data.Game.ThirdRound.Chronologies.Count)
                    {
                        process.Data.ThirdRoundResult.QuestionIndex   = 0;
                        process.Data.ThirdRoundResult.ThirdRoundState = ThirdRoundState.MelodyGuess;
                    }
                    break;

                case ThirdRoundState.MelodyGuess:
                    if (process.Data.ThirdRoundResult.QuestionIndex == process.Data.Game.ThirdRound.MelodyGuesses.Count)
                    {
                        process.Data.ThirdRoundResult.QuestionIndex   = 0;
                        process.Data.ThirdRoundResult.ThirdRoundState = ThirdRoundState.Association;
                    }
                    break;

                case ThirdRoundState.Association:
                    if (process.Data.ThirdRoundResult.QuestionIndex == process.Data.Game.ThirdRound.Associations.Count)
                    {
                        //FirstRoundShowAd(process.Data.Id);
                        ThirdRoundBreak(gameProcessId);
                        return;
                    }
                    break;
                }

                process.Data.ThirdRoundResult.State = PlayState.SelectQuestion;

                await gameProcessService.Save();



                var timer = new Timer
                {
                    Interval  = roundOptions.Value.ThirdRoundReceivingAnswersInterval,
                    AutoReset = false
                };
                timer.Elapsed += (sender, e) => ThirdRoundReceivingAnswers(process.Data.Id);
                timer.Start();
            }
        }