private void AddToNewGameSession(AddPlayerMessage addPlayerMessage, CancellationToken cancellationToken) { var gameSessionToken = this.gameSessionTokenFactory.CreateGameSessionToken(); var gameSession = new GameSession(this.gameManagerFactory.Create(), this.maximumPlayerCount, this.playerCardRepository, gameSessionToken, cancellationToken, this.loggerFactory); gameSession.Start(); gameSession.AddPlayer(addPlayerMessage); this.gameSessions.Add(gameSessionToken, gameSession); }
/// <summary> /// Tries to connect player to GameSession /// </summary> /// <param name="i_player">Player name</param> /// <returns>True if player could be connected, false if game is full or started and false with exception if game was removed (or other reasons for exception throw)</returns> public async Task <ServerResponseInfo <bool, Exception> > ConnectPlayerAsync(string i_player, byte[] i_address) { ServerResponseInfo <bool, Exception> res = new ServerResponseInfo <bool, Exception>(); try { //Get GameSession from StateManager GameSession gameSession = await this.StateManager.GetStateAsync <GameSession>("gamesession"); //Adds player to game if posible if (gameSession.AddPlayer(i_player, i_address)) { //If first player in lobby if (gameSession.playerCount == 1) { await this.UnregisterReminderAsync(GetReminder("RemoveIfEmpty")); //Registers LobyCheck reminder await this.RegisterReminderAsync("LobbyCheck", null, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10)); } //Saves "gamesession" state await this.StateManager.SetStateAsync("gamesession", gameSession); ActorEventSource.Current.Message(ServiceUri.AbsoluteUri); ILoginService login = ServiceProxy.Create <ILoginService>(new Uri(ServiceUri.AbsoluteUri.Replace("GameManagerActorService", "LoginService"))); //Adds player to server (SQL Register) await login.AddPlayerAsync(Id.ToString()); //Returns true res.info = true; return(res); } //Saves "gamesession" state await this.StateManager.SetStateAsync("gamesession", gameSession); //Returns false (player couldn't be added: game full or started) res.info = false; return(res); } //Catch exception if "gamesesion" state doesn't exist catch (Exception e) { //Returns false and exception (player couldn't be added: game removed) res.info = false; res.exception = e; return(res); } }
public override void StartExecution(Action <Command> OnCommandFinished) { base.StartExecution(OnCommandFinished); List <string> playerOrder = new List <string>(); List <Color> usedColors = new List <Color>(); foreach (Photon.Realtime.Player p in PhotonNetwork.CurrentRoom.Players.Values) { Color mainColor; do { mainColor = Keys.Gameplay.PLAYER_COLORS[Random.Range(0, 6)]; }while (usedColors.Contains(mainColor)); usedColors.Add(mainColor); Player player; if (session.roomOwner.IsLocal) { player = new Player(p, mainColor, Keys.Board.Backlight.SECONDARY_COLOR); } else { player = new Player(p); } session.AddPlayer(player); if (session.roomOwner.IsLocal) { playerOrder.Add(player.GetName()); } } if (session.roomOwner.IsLocal) { session.playerOrder = playerOrder; } }
// When a player creates a new public async Task NewGame(string d) { int dimension = Convert.ToInt32(d); if (_gameSessions.Games.Any(g => g.Players.Count() == 1)) { await JoinGame(); } var newKey = Guid.NewGuid().ToString(); GameSession newGame = new GameSession(dimension) { SessionKey = newKey }; newGame.AddPlayer(Context.ConnectionId); _gameSessions.Games.Add(newGame); await Groups.AddToGroupAsync(Context.ConnectionId, newKey.ToString()); await Clients.Caller.SendAsync("WaitingPlayer2"); await Clients.Others.SendAsync("EnableJoin"); }
public GameSessionWindow() { InitializeComponent(); gameSession.AddPlayer(new Player(new GreenPlayer())); }