public void MenuOptionMouseUp(object sender, System.Windows.Input.MouseEventArgs e) { try { if (m_MouseDownSender != sender) return; Image img = sender as Image; string selected = img.Name; if (selected == "CreateGame") { ClientGameEngine.Get().ChangeState(NewGameState.Get()); } else if (selected == "JoinGame") { if (m_SelectedGame == null) { RenderMessageDialog.RenderMessage("You need to select a game to join!"); } else { if (m_SelectedGame.HasPassword) { RenderMessageDialog.RenderInput("Please enter the password: "******"MainMenu") { ClientGameEngine.Get().ChangeState(MainMenuState.Get()); } } catch (Exception) { } }
private void ProcessMessages() { // All generic server messages are handled here m_GenericServerMessageSubscriber = MessageSubject .Where(message => message is GenericServerMessage) .Subscribe(message => { var genericMessage = message as GenericServerMessage; switch (genericMessage.MessageEnum) { case ServerMessage.ServerMessageEnum.StartServer: break; case ServerMessage.ServerMessageEnum.ServerStarted: break; default: ConsoleLogger.Push("Unhandled GenericServerMessage was received: " + genericMessage.MessageEnum.ToString()); break; } }); // All server messages are handled here m_ServerMessageSubscriber = MessageSubject .Where(message => message is ServerMessage && !(message is GenericServerMessage)) .Subscribe(message => { if (message is CreateGameMessage) { //CommandCreateGame commandCreateGame = command as CommandCreateGame; // create the new game instance CreateGameMessage gameMessage = message as CreateGameMessage; string gameId = Guid.NewGuid().ToString(); BesiegedGameInstance gameInstance = new BesiegedGameInstance(gameId, gameMessage.GameName, gameMessage.MaxPlayers, gameMessage.Password, gameMessage.ClientId); m_Games.GetOrAdd(gameId, gameInstance); JoinGameMessage join = new JoinGameMessage() { ClientId = message.ClientId, Password = gameMessage.Password, GameId = gameId }; // add the client that requested the new game to the game instance m_MessageQueue.Add(join); //string capacity = string.Format("{0}/{1} players", gameInstance.Players.Count, gameInstance.MaxPlayers); // notify all connect clients of the updated game instance //GameInfoMessage gameInfo = new GameInfoMessage(gameInstance.GameId, gameInstance.Name, capacity, gameInstance.IsGameInstanceFull, gameInstance.Password != string.Empty ? true : false); ConsoleLogger.Push(string.Format("{0} has created a new game called: {1}", m_ConnectedClients[message.ClientId].Name, gameInstance.Name)); //NotifyAllConnectedClients(gameInfo.ToXml()); } }); // Game messages that are no longer valid are handled here m_BadGameMessageSubscriber = MessageSubject .Where(message => message is GameMessage && !m_Games.ContainsKey(message.GameId)) .Subscribe(message => { GenericClientMessage notFound = new GenericClientMessage() { MessageEnum = ClientMessage.ClientMessageEnum.GameNotFound }; m_ConnectedClients[message.ClientId].Callback.SendMessage(notFound.ToXml()); }); }