///<exception cref="ServiceException">ServiceException</exception> public IGameSession Create(SessionGamePlayer sessionPlayer1, SessionGamePlayer sessionPlayer2 = null) { if (sessionPlayer2 == null) { sessionPlayer2 = this.GetRandomSessionPlayer2(sessionPlayer1); } var newSession = new GameSession(sessionPlayer1, sessionPlayer2); var existSession = this.sessionRepository.Exist(s => s.State == SessionState.Active && s.Name == newSession.Name); if (existSession) { var errorMessage = string.Format("There is already an active session for players {0} and {1}", sessionPlayer1.Information.Name, sessionPlayer2.Information.Name); throw new ServiceException(errorMessage); } try { this.sessionRepository.Create(newSession); } catch (DataException gameDataEx) { var errorMessage = string.Format("An error occured when creating the session {0}", newSession.Name); throw new ServiceException(errorMessage, gameDataEx); } return newSession; }
public void Initialize() { this.serializer = new JsonSerializer(); this.player1 = new User { DisplayName = "Player 1", Name = "player1" }; this.player2 = new User { DisplayName = "Player 2", Name = "player2" }; this.sessionPlayer1 = new TestSessionPlayer() { Information = this.player1, SessionName = this.sessionName }; this.sessionPlayer2 = new TestSessionPlayer() { Information = this.player2, SessionName = this.sessionName }; this.session = new GameSession(this.sessionPlayer1, this.sessionPlayer2); this.playerServiceMock = new Mock<IUserService>(); this.sessionServiceMock = new Mock<ISessionService>(); this.notificationServiceMock = new Mock<INotificationService>(); this.playerFactoryMock = new Mock<ISessionPlayerFactory>(); this.playerSetupMock = new Mock<ISessionPlayerSetup>(); this.inviteDecoratorMock = new Mock<IGameInviteDecorator>(); }
public GameSession(SessionGamePlayer player1, SessionGamePlayer player2) { this.Player1 = player1; this.Player1Name = player1.Information.Name; this.Player2 = player2; this.Player2Name = player2.Information.Name; this.Name = string.Concat(this.Player1Name, "-vs-", this.Player2Name); this.State = SessionState.Pending; this.Player1.SessionName = this.Name; this.Player1.PendingToMove = true; this.Player2.SessionName = this.Name; }
private SessionGamePlayer GetRandomSessionPlayer2(SessionGamePlayer sessionPlayer1) { var randomPlayer2 = this.userService.GetRandom(userNameToExclude: sessionPlayer1.Information.Name); if (randomPlayer2 == null) { var errorMessage = "There are no users available to play"; throw new ServiceException(errorMessage); } return this.sessionPlayerFactory.Create(randomPlayer2); }
public void GetPlayerReady(CreateGameClientMessage createGameRequest, SessionGamePlayer gamePlayer) { return; }
public void GetPlayerReady(AcceptGameClientMessage gameAcceptedRequest, SessionGamePlayer gamePlayer) { return; }