예제 #1
0
        public GameLobby(bool isHosted, string clientName)
        {
            IsHosted   = isHosted;
            ClientName = clientName;

            if (IsHosted)
            {
                LobbyMenu = new Menu
                            (
                    Position.Bottom, Align.Center, Fonts.RegularConsolas16,
                    ("Start Game", ActionType.Update, () =>
                {
                    ((GDarts)Game.SceneManager[GameState.Game]).Client = _client;
                    ((GDarts)Game.SceneManager[GameState.Game]).ClientName = ClientName;
                    ((GDarts)Game.SceneManager[GameState.Game]).StartGame(true);
                    TcpAsyncServer.StopInterfaceListening();
                    _udpServer.StopListen();
                    Game.SceneManager.ActiveState = GameState.Game;
                }
                    ),
                    ("Exit Lobby", ActionType.Update, ExitLobby)
                            );
            }
            else
            {
                LobbyMenu = new Menu(Position.Bottom, Align.Center, Fonts.RegularConsolas16,
                                     ("Exit Lobby", ActionType.Update, ExitLobby));
            }
        }
예제 #2
0
 public void StartGame(bool isHosted)
 {
     Client.handleViewData += ViewGameInformation;
     if (isHosted)
     {
         TcpAsyncServer.SendStartGameDataMessage();
     }
 }
        public MessagingHostFeature(IConnectionManager connectionManager, ILoggerFactory loggerFactory, TcpAsyncServer tcpAsyncServer, INodeStats nodeStats, IMessageNodeRepository messageNodeRepository)
        {
            this.connectionManager     = connectionManager;
            this.tcpAsyncServer        = tcpAsyncServer;
            this.logger                = loggerFactory.CreateLogger(this.GetType().FullName);
            this.messageNodeRepository = messageNodeRepository;

            nodeStats.RegisterStats(AddComponentStatsAsync, StatsType.Component, GetType().Name);
            nodeStats.RegisterStats(AddInlineStats, StatsType.Inline, GetType().Name, 800);
        }
예제 #4
0
        private void ExitLobby()
        {
            if (IsHosted)
            {
                TcpAsyncServer.StopInterfaceListening();
                _udpServer.StopListen();
                TcpAsyncServer.SafeCloseAllSockets();
            }
            else
            {
                _client.Client.Socket.Close();
            }

            Game.SceneManager.ActiveState = GameState.MainMenu;
        }
예제 #5
0
        public override void Initialize()
        {
            if (IsHosted)
            {
                _udpServer = new UdpServer(12345, 11000, "GDarts");
                _udpServer.StartListen();
                TcpAsyncServer.StartTcpServer();
            }

            ConnectionManager connection;

            if (IP != null)
            {
                if (Port != null)
                {
                    connection = new ConnectionManager(IP, Port.Value);
                }
                else
                {
                    connection = new ConnectionManager(IP, Game.ConfigManager.TcpPort);
                }
            }
            else
            {
                var udpClient = new UdpClient("GDarts", 11000, 3000);
                if (udpClient.SendToBroadcast())
                {
                    connection = new ConnectionManager(IPAddress.Parse(udpClient.ServerAddress.Address.ToString()),
                                                       udpClient.TcpPort);
                }
                else
                {
                    return;
                }
            }

            _client = new TcpAsyncClient(connection);
            _client.handleConnection += AddPlayerInLobby;
            _client.handleGame       += JoinGame;
            _client.SendFindLobbyMessage();


            base.Initialize();
        }
예제 #6
0
        public override void Update(GameTime gameTime)
        {
            if (GMouse.IsButtonPressed(MouseButton.Left))
            {
                if (Client.ReceiverGameData.WinPlayer != null)
                {
                    Thread.Sleep(400);
                    TcpAsyncServer.SafeCloseAllSockets();
                    Game.SceneManager.ActiveState = GameState.MainMenu;
                    foreach (var label in PlayerLabels)
                    {
                        label.Clear();
                    }
                }
                SendShootData();
            }

            foreach (var label in PlayerLabels)
            {
                label.Update(gameTime);
            }
        }