Example #1
0
        void ServerGame_PlayerLeaved(object sender, PlayerEventArgs e)
        {
            if (m_serverGame.Players.Count == 1) {
                m_serverGame.Stop();
                m_serverGame.PlayerJoined -= (ServerGame_PlayerJoined);
                m_serverGame.PlayerLeaved -= (ServerGame_PlayerLeaved);
            }

            this.Refresh();
        }
Example #2
0
        void ServerGame_PlayerPrepared(object sender, PlayerEventArgs e)
        {
            if (m_serverGame.Players.Count == m_serverGame.MaxPlayers) {
                if (m_serverGame.IsReady) {
                    m_serverGame.Start();
                    //break;
                }
                //DateTime dt = DateTime.Now;
                //while (true) {

                //    if (DateTime.Now.Subtract(dt).Seconds > 15) {
                //        // time out
                //        MessageBox.Show("Game starting time out.");
                //        m_serverGame.Stop();
                //        break;
                //    }

                //    System.Threading.Thread.Sleep(0);
                //}
            }
        }
Example #3
0
        void ClientGame_PlayerLeft(object sender, PlayerEventArgs e)
        {
            ClientGame game = m_game as ClientGame; //sender as ClientGame;
            Player player = e.Player;
            if (null == game || null == player || null == player.InfoPanel)
                return;

            //TODO: uses skin
            player.InfoPanel.SetString("info", string.Format("{0} has left the game.", player.Name),
                 new Font("MSYH", 8), Brushes.Gray, 5, player.InfoPanel.Height - 20, 0, 0);

            this.Refresh();
        }
Example #4
0
        void ServerGame_PlayerJoined(object sender, PlayerEventArgs e)
        {
            Player player = e.Player;
            //TODO: uses skin
            m_networkGameInfoPanel.SetString("info", string.Format(
                "Player {0} joined. Waiting for rest client players ({1}/{2}) ...",
                    player.Name, m_serverGame.Players.Count, m_serverGame.MaxPlayers),
                new Font("MSYH", 8), Brushes.CadetBlue, 5, 5, 0, 0);
            //if (m_game.Players.Count < m_serverGame.Players.Count) {
            //    this.InitPlayer(player);
            //    m_game.AddPlayer(player);
            //}

            this.Refresh();
        }
Example #5
0
        void ClientGame_PlayerJoined(object sender, PlayerEventArgs e)
        {
            ClientGame game = m_game as ClientGame; //sender as ClientGame;
            Player player = e.Player;
            if (null == game || null == player)
                return;

            this.InitPlayer(player);

            //TODO: uses skin
            player.InfoPanel.SetString("info",
                string.Format("{0} has joined the game. Waiting for other players...", player.Name),
                new Font("MSYH", 8), Brushes.Gray, 5, player.InfoPanel.Height - 20, 0, 0);

            this.Refresh();
        }
Example #6
0
        void ClientGame_Left(object sender, PlayerEventArgs e)
        {
            ClientGame game = m_game as ClientGame; //sender as ClientGame;
            Player player = e.Player;
            if (null == game || null == player || null == player.InfoPanel)
                return;
            //TODO: uses skin
            player.InfoPanel.SetString("info", "You have left the game.",
                 new Font("MSYH", 8), Brushes.Gray, 5, player.InfoPanel.Height - 20, 0, 0);
            game.Stop();
            game.Joined -= (ClientGame_Joined);
            game.Left -= (ClientGame_Left);
            game.PlayerJoined -= (ClientGame_PlayerJoined);
            game.PlayerLeft -= (ClientGame_PlayerLeft);
            game.Dispose();
            game = null;

            this.Refresh();
        }
Example #7
0
        void ClientGame_Joined(object sender, PlayerEventArgs e)
        {
            ClientGame game = m_game as ClientGame; //sender as ClientGame;
            Player player = e.Player;
            if (null == game || null == player || null == player.InfoPanel)
                return;

            //TODO: uses skin
            player.InfoPanel.SetString("info", "You have joined the game. Waiting for other players...",
                 new Font("MSYH", 8), Brushes.Gray, 5, player.InfoPanel.Height - 20, 0, 0);

            this.Refresh();
        }
Example #8
0
 void OnDisconnected(object sender, EventArgs e)
 {
     if (this.Left != null && null != m_player) {
         PlayerEventArgs arg = new PlayerEventArgs();
         arg.Player = m_player;
         this.Left(this, arg);
     }
 }
Example #9
0
 void OnConnected(object sender, EventArgs e)
 {
     m_client.Name = m_client.LocalEndPoint.ToString();
     m_player.HostName = m_client.Name;
     if (this.Joined != null && null != m_player) {
         PlayerEventArgs arg = new PlayerEventArgs();
         arg.Player = m_player;
         this.Joined(this, arg);
     }
 }