コード例 #1
0
        /// <summary>
        /// Get the current game session from the browser session storage.
        /// </summary>
        /// <param name="service">GameSessionService.</param>
        /// <returns>IUserSession.</returns>
        internal async Task <UserSession> GetUserSessionAsync(GameSessionService service)
        {
            bool saveBrowserStorage    = false;
            BrowserSessionStorage data = await service.GetBrowserSessionStorageAsync();

            if (data == null)
            {
                data = new BrowserSessionStorage
                {
                    SessionId = Guid.NewGuid().ToString(),
                };
                saveBrowserStorage = true;
            }
            else if (string.IsNullOrWhiteSpace(data.SessionId))
            {
                data.SessionId     = Guid.NewGuid().ToString();
                saveBrowserStorage = true;
            }
            else if (this.sessions.TryGetValue(data.SessionId, out UserSession foundSession))
            {
                await SetUserAsync(foundSession, service, data, saveBrowserStorage);

                return(foundSession);
            }

            var session = new UserSession(data.SessionId);

            await SetUserAsync(session, service, data, saveBrowserStorage);

            //// TODO: How/when to remove this user from list?  Or is there another way to do this.
            return(this.sessions.TryAdd(session.SessionId, session) ? session : this.sessions[session.SessionId]);
        }
コード例 #2
0
 public Playground(GameSession gameSession)
 {
     InitializeComponent();
     this.gameSession          = gameSession;
     UserProfile.GamaSessionId = gameSession.Id;
     this.riddleService        = new RiddleService();
     this.userService          = new UserService();
     this.hintHistoryService   = new GameSessionUseHintHistoryService();
     this.answerHistoryService = new AnswerHistoryService();
     this.gameSessionService   = new GameSessionService();
     this.textBoxModelsList    = InitTextBoxModels();
     Notify                  = null;
     Notify                 += FunctionOfUsingHint;
     SurrenderNotify         = null;
     SurrenderNotify        += SurrenderAction;
     rivalFinishedNotify     = null;
     rivalFinishedNotify    += RivalFinishedAction;
     rivalExitedNotify       = null;
     rivalExitedNotify      += RivalExitedAction;
     this.dispose            = true;
     this.timeTimer          = new DateTime(1, 1, 1, 1, 0, 0).AddSeconds(UserProfile.Level.LevelTime);
     this.totalTime          = new DateTime(1, 1, 1, 1, 0, 0);
     this.pointsForOneRiddle = 10;
     this.totalUserPoints    = 0;
     this.TimeOver           = null;
 }
コード例 #3
0
        /// <summary>
        /// Get the current game user class.
        /// </summary>
        /// <param name="gameSessionService">GameSessionService.</param>
        /// <param name="userId">User ID.</param>
        /// <returns>GameUser.</returns>
        internal async Task <User> GetUserAsync(GameSessionService gameSessionService, string userId = null)
        {
            if (!string.IsNullOrWhiteSpace(userId))
            {
                if (this.users.TryGetValue(userId, out User value))
                {
                    return(value);
                }
            }

            BrowserLocalStorage data = await gameSessionService.GetBrowserLocalStorageAsync();

            if (data == null)
            {
                data = new BrowserLocalStorage
                {
                    UserId = Guid.NewGuid().ToString(),
                };
                await gameSessionService.SetBrowserLocalStorageAsync(data);
            }
            else if (string.IsNullOrWhiteSpace(data.UserId))
            {
                data.UserId = Guid.NewGuid().ToString();
                await gameSessionService.SetBrowserLocalStorageAsync(data);
            }
            else if (this.users.TryGetValue(data.UserId, out User foundUser))
            {
                return(foundUser);
            }

            var user = new User(data.UserId);

            //// TODO: How/when to remove this user from list?  Or is there another way to do this.
            return(this.users.TryAdd(user.Id, user) ? user : this.users[user.Id]);
        }
コード例 #4
0
ファイル: SendRequest.cs プロジェクト: MaximFil/RiddlesClient
 public SendRequest(bool dispose = true)
 {
     InitializeComponent();
     userService             = new UserService();
     levelService            = new LevelService();
     gameSessionService      = new GameSessionService();
     this.dispose            = dispose;
     UserProfile.CurrentForm = this;
 }
コード例 #5
0
        public void Setup()
        {
            _mockGameSessionStorage       = Substitute.For <IGameSessionStorage>();
            _mockGameStorage              = Substitute.For <IGameStorage>();
            _mockGameErrandStorage        = Substitute.For <IGameErrandStorage>();
            _mockGameSessionErrandStorage = Substitute.For <IGameSessionErrandStorage>();
            _mockGameSessionEventStorage  = Substitute.For <IGameSessionEventStorage>();

            _service = new GameSessionService(_mockGameSessionStorage, _mockGameStorage, _mockGameErrandStorage, _mockGameSessionErrandStorage, _mockGameSessionEventStorage);
        }
コード例 #6
0
        public void RematchStartedWhenConsensusIsReached()
        {
            var sut   = new GameSessionService("asdfgh", _gameplayMock.Object);
            var state = sut.RequestNewGame(1);

            _gameplayMock.Verify(g => g.RestartGame(), Times.Never);
            Assert.IsFalse(state.RematchStarted);

            state = sut.RequestNewGame(2);
            _gameplayMock.Verify(g => g.RestartGame(), Times.Once);
            Assert.IsTrue(state.RematchStarted);
        }
コード例 #7
0
        public void DrawIsExecutedWhenConsensusIsReached()
        {
            var sut   = new GameSessionService("asdfgh", _gameplayMock.Object);
            var state = sut.PlayerWantsToDraw(1);

            _gameplayMock.Verify(g => g.Draw(), Times.Never);
            Assert.IsFalse(state.DrawExecuted);
            Assert.AreEqual(1, state.DrawRequestedByPlayer);

            state = sut.PlayerWantsToDraw(2);
            _gameplayMock.Verify(g => g.Draw(), Times.Once);
            Assert.IsTrue(state.DrawExecuted);
        }
コード例 #8
0
ファイル: ResultForm.cs プロジェクト: MaximFil/RiddlesClient
 public ResultForm(string totalTime, int userTotalPoints, string rivalTotalTime, int rivalTotalPoints, bool?surrender = null, bool?exited = null, bool dispose = true, bool?timeOver = null)
 {
     InitializeComponent();
     this.TotalTime          = totalTime;
     this.TotalPoints        = userTotalPoints;
     this.RivalTotalTime     = rivalTotalTime;
     this.RivalTotalPoints   = rivalTotalPoints;
     this.Surrender          = surrender;
     this.RivalExited        = exited;
     this.TimeOver           = timeOver;
     this.gameSessionService = new GameSessionService();
     this.userService        = new UserService();
     UserProfile.CurrentForm = this;
     this.dispose            = dispose;
 }
コード例 #9
0
        public void GameStartsWhenTwoPlayersAreAdded()
        {
            var sut = new GameSessionService("asdfgh", _gameplayMock.Object);

            _gameplayMock.SetupGet(g => g.PlayerOne).Returns(new Player("Anders", true));
            var state = sut.AddPlayer("Anders");

            Assert.IsFalse(state.IsReady);

            _gameplayMock.SetupGet(g => g.PlayerTwo).Returns(new Player("Edith", false));
            _gameplayMock.Setup(g => g.CanStart()).Returns(true);
            state = sut.AddPlayer("Edith");

            Assert.IsTrue(state.IsReady);
            _gameplayMock.Verify(g => g.AddPlayer(It.IsAny <string>()), Times.Exactly(2));
        }
コード例 #10
0
        private void SceneCreated(Scene scene)
        {
            var pluginName = scene.GetHostMetadata("stormancer.plugins.matchmaking");

            if (!string.IsNullOrEmpty(pluginName))
            {
                var matchmakingService = new MatchmakingService(scene);
                scene.DependencyResolver.RegisterComponent(matchmakingService);
            }

            pluginName = scene.GetHostMetadata("stormancer.gamesession");
            if (!string.IsNullOrEmpty(pluginName))
            {
                var gameSessionService = new GameSessionService(scene);
                scene.DependencyResolver.RegisterComponent(gameSessionService);
            }
        }
コード例 #11
0
        private static async Task SetUserAsync(UserSession session, GameSessionService service, BrowserSessionStorage data, bool saveBrowserStorage)
        {
            if (session.User == null)
            {
                session.User = await service.GameEngineService.Users.GetUserAsync(service, data.UserId);
            }

            if (string.IsNullOrWhiteSpace(data.UserId))
            {
                data.UserId        = session.User.Id;
                saveBrowserStorage = true;
            }

            if (saveBrowserStorage)
            {
                await service.SetBrowserSessionStorageAsync(data);
            }
        }
コード例 #12
0
 public LobbyHub(LobbyService lobbyService, GameSessionService gameSessionService)
 {
     _lobbyService       = lobbyService;
     _gameSessionService = gameSessionService;
 }
コード例 #13
0
ファイル: HubHelper.cs プロジェクト: MaximFil/RiddlesClient
 public HubHelper()
 {
     gameSessionService = new GameSessionService();
 }
コード例 #14
0
 public GameSessionController()
 {
     this.gameSessionService = new GameSessionService();
 }
コード例 #15
0
 public GameSessionManager()
 {
     _ChatStore       = new ChatStorage();
     _HubService      = new HubService();
     _GSessionService = new GameSessionService();
 }