Beispiel #1
0
        public async Task Begin()
        {
            // Arrange
            var activity = new Activity()
            {
                ActivityType = ActivityType.Message,
                ChatId       = 15,
            };
            var turnContext = A.Fake <ITurnContext>();

            A.CallTo(() => turnContext.Activity).Returns(activity);
            var imageHuntState = new ImageHuntState()
            {
                Status = Status.Started
            };

            A.CallTo(() => turnContext.GetConversationState <ImageHuntState>()).Returns(imageHuntState);
            // Act
            await _target.Begin(turnContext);

            // Assert
            A.CallTo(() => turnContext.GetConversationState <ImageHuntState>()).MustHaveHappened();
            A.CallTo(() => turnContext.ReplyActivity(A <string> ._)).MustHaveHappened();
            A.CallTo(() => turnContext.End()).MustHaveHappened();
            A.CallTo(() => _actionWebService.LogAction(A <GameActionRequest> ._, A <CancellationToken> ._))
            .MustHaveHappened();
            A.CallTo(() => _logger.Log(A <LogLevel> ._, A <EventId> ._, A <object> ._, A <Exception> ._,
                                       A <Func <object, Exception, string> > ._))
            .WithAnyArguments()
            .MustHaveHappened();
            Check.That(imageHuntState.Status).Equals(Status.Ended);
        }
Beispiel #2
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Initialized)
            {
                LogInfo <ImageHuntState>(turnContext, "Game not initialized");
                await turnContext.ReplyActivity("Le chat n'a pas été initialisé, impossible de commencer maintenant!");

                await turnContext.End();

                return;
            }
            LogInfo <ImageHuntState>(turnContext, "Start Game");

            var gameActionRequest = new GameActionRequest()
            {
                Action    = (int)ImageHuntWebServiceClient.Action.StartGame,
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };

            state.Status = Status.Started;
            await _actionWebService.LogAction(gameActionRequest);

            await turnContext.ReplyActivity($"La chasse commence maintenant! Bonne chance!");

            await turnContext.End();
        }
Beispiel #3
0
        public override async Task Begin(ITurnContext turnContext)
        {
            var state = turnContext.GetConversationState <ImageHuntState>();

            if (state.Status != Status.Started)
            {
                LogInfo <ImageHuntState>(turnContext, "The game had not started!");
                await turnContext.ReplyActivity("La partie n'a pas encore commencée, vous ne pouvez par l'arrêter!");

                await turnContext.End();
            }
            _logger.LogInformation($"The Hunt of GameId={state.GameId} for teamid={state.TeamId} had ended.");
            var gameActionRequest = new GameActionRequest()
            {
                Action    = (int)ImageHuntWebServiceClient.Action.EndGame,
                GameId    = state.GameId,
                TeamId    = state.TeamId,
                Latitude  = state.CurrentLatitude,
                Longitude = state.CurrentLongitude
            };

            state.Status = Status.Ended;
            await _actionWebService.LogAction(gameActionRequest);

            await turnContext.ReplyActivity(
                $"La chasse vient de prendre fin, vos actions ont été enregistrée et un orga va les valider.");

            await turnContext.End();
        }
Beispiel #4
0
        static async Task InsertRandomPosition(int gameId, int minTeamId, int maxTeamId, double latitude, double longitude, int interval = 15000)
        {
            var random            = new Random((int)DateTime.Now.Ticks);
            var gameActionRequest = new GameActionRequest()
            {
                GameId    = gameId,
                Latitude  = latitude,
                Longitude = longitude,
            };

            do
            {
                gameActionRequest.Action     = random.Next(0, 7);
                gameActionRequest.TeamId     = random.Next(minTeamId, maxTeamId + 1);
                gameActionRequest.TeamId     = random.Next(minTeamId, maxTeamId + 1);
                gameActionRequest.Latitude  += 0.001 * (random.NextDouble() - 0.5);
                gameActionRequest.Longitude += 0.001 * (random.NextDouble() - 0.5);
                try
                {
                    await _actionWebService.LogAction(gameActionRequest);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                Thread.Sleep(interval);
            } while (true);
        }