/// <summary>
        /// Once all players are ready, adds players to the Game controller and starts the game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void start_game_Click(object sender, EventArgs e)
        {
            var ds  = NetworkClasses.GetServer(User.PlayerId, User.LocalIp);
            var row = ds.Tables[0].Rows[0];

            var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

            //Host
            LobbyController.AddPlayer(int.Parse(grabber.Tables[0].Rows[0]["Player_ID"].ToString()), grabber.Tables[0].Rows[0]["_Character"].ToString());

            for (var i = 2; i <= 6; i++)
            {
                if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                {
                    continue;
                }
                grabber = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                LobbyController.AddPlayer(int.Parse(grabber.Tables[0].Rows[0]["Player_ID"].ToString()), grabber.Tables[0].Rows[0]["_Character"].ToString());
            }
            NetworkClasses.UpdateServerValue("Status", "In Progress", "Host", User.PlayerId);
            NetworkClasses.UpdateUserValue("User_List", "Online", "In Game", User.PlayerId);
            LobbyController.StartGame();
            Host.StartGame();
            _timer.Stop();
            //_chat.Dispose();
            _gameTimer.Start();
            if (!_profile.IsDisposed)
            {
                _profile.Dispose();
            }
            Hide();

            //MainMenuForm waiter = new MainMenuForm();
            //waiter.Show();
        }
Beispiel #2
0
        /// <summary>
        /// Updates the list of players with the current information about the server via the database
        /// </summary>
        private void UpdateList()
        {
            playerList.Items.Clear();
            try
            {
                var ds  = NetworkClasses.GetServer(Client.Conn);
                var row = ds.Tables[0].Rows[0];

                var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

                //Host
                var listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
                //Add the row entry to the listview
                playerList.Items.Add(listItem);

                for (var i = 2; i <= 6; i++)
                {
                    if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                    {
                        continue;
                    }
                    grabber  = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                    listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                    listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
                    playerList.Items.Add(listItem);
                }
            }
            catch (Exception) //Thrown if server no longer exists
            {
                Form form = new MainMenuForm();
                form.Show();
                _timer.Stop();
                Client.ClientStop();
                NetworkClasses.UpdateCharacter(User.PlayerId, null);
                MessageBox.Show("Host left the game", "Server Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Dispose();
            }
        }
        /// <summary>
        /// Updates the list of players with the current information about the server via the database
        /// </summary>
        private void UpdateList()
        {
            //Resets the view
            playerList.Items.Clear();

            //Gets server info and puts it into a dataset
            var ds      = NetworkClasses.GetServer(User.PlayerId, User.LocalIp);
            var row     = ds.Tables[0].Rows[0];
            var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

            //Gets ping values for all players
            var pings = new List <int>();

            while (pings.Count < 1)
            {
                pings = Host.GetPing();
            }

            //Host
            var listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());

            listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
            listItem.SubItems.Add(pings[0].ToString() + " ms");

            //Add the clients to the listview
            playerList.Items.Add(listItem);
            for (var i = 2; i <= 6; i++)
            {
                if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                {
                    continue;
                }
                grabber  = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                listItem.SubItems.Add(grabber.Tables[0].Rows[0]["_Character"].ToString());
                listItem.SubItems.Add(pings[i - 1].ToString() + " ms");
                playerList.Items.Add(listItem);
            }
        }
        /// <summary>
        /// Once all players are ready, adds players to the Game controller and starts the game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void start_game_Click(object sender, EventArgs e)
        {
            var ds  = NetworkClasses.GetServer(User.PlayerId, User.LocalIp);
            var row = ds.Tables[0].Rows[0];

            var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

            //Host
            LobbyController.AddPlayer(int.Parse(grabber.Tables[0].Rows[0]["Player_ID"].ToString()), grabber.Tables[0].Rows[0]["_Character"].ToString());

            for (var i = 2; i <= 6; i++)
            {
                if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                {
                    continue;
                }
                grabber = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                LobbyController.AddPlayer(int.Parse(grabber.Tables[0].Rows[0]["Player_ID"].ToString()), grabber.Tables[0].Rows[0]["_Character"].ToString());
            }
            NetworkClasses.UpdateServerStatus("In Progress", User.PlayerId);
            LobbyController.StartGame();
            Host.StartGame();
        }
        /// <summary>
        /// Updates the list of players with the current information about the server via the database
        /// </summary>
        private void UpdateList()
        {
            var done = true;
            //Gets server info and puts it into a dataset
            var ds = NetworkClasses.GetServer(User.PlayerId, User.LocalIp);

            var currentNumPlayers = NetworkClasses.GetNumPlayers(int.Parse(ds.Tables[0].Rows[0]["Server_ID"].ToString()));

            if (_players.Count == currentNumPlayers && _players.Count >= 1)
            {
                //Check if characters have changed
                var newPlayerChars = new List <DataSet>
                {
                    NetworkClasses.GetPlayer(int.Parse(ds.Tables[0].Rows[0]["Host"].ToString()))
                };
                for (var i = 2; i <= 6; i++)
                {
                    if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["Player_" + i].ToString()))
                    {
                        newPlayerChars.Add(
                            NetworkClasses.GetPlayer(int.Parse(ds.Tables[0].Rows[0]["Player_" + i].ToString())));
                    }
                }
                for (var i = 0; i < newPlayerChars.Count; i++)
                {
                    if (_players[i].Tables[0].Rows[0]["_Character"].ToString() !=
                        newPlayerChars[i].Tables[0].Rows[0]["_Character"].ToString())
                    {
                        done = false;
                        break;
                    }
                }
                if (done)
                {
                    return;
                }
            }

            //Updating
            _players.Clear();
            playerList.Items.Clear();
            var row     = ds.Tables[0].Rows[0];
            var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));

            _players.Add(grabber);
            var _character = "";

            //Host
            var listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());

            _character = grabber.Tables[0].Rows[0]["_Character"].ToString();
            listItem.SubItems.Add(_character);

            //Add the clients to the listview
            playerList.Items.Add(listItem);
            for (var i = 2; i <= 6; i++)
            {
                if (string.IsNullOrEmpty(row["Player_" + i].ToString()))
                {
                    continue;
                }
                grabber = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                _players.Add(grabber);
                listItem   = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                _character = grabber.Tables[0].Rows[0]["_Character"].ToString();
                listItem.SubItems.Add(_character);

                playerList.Items.Add(listItem);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Updates the list of players with the current information about the server via the database
        /// </summary>
        private void UpdateList()
        {
            var done = true;

            try
            {
                //Gets server info and places it into a dataset
                var ds = NetworkClasses.GetServer(Client.Conn);

                //Checks if game has started
                if (ds.Tables[0].Rows[0]["Status"].ToString() == "In Progress")
                {
                    NetworkClasses.UpdateUserValue("User_List", "Online", "In Game", User.PlayerId);
                    //MainMenuForm form = new MainMenuForm();
                    //form.Show();
                    //_chat.Dispose();
                    if (!_profile.IsDisposed)
                    {
                        _profile.Dispose();
                    }
                    _timer.Stop();
                    _gameTimer.Start();
                    Hide();
                    return;
                }

                var currentNumPlayers = NetworkClasses.GetNumPlayers(int.Parse(ds.Tables[0].Rows[0]["Server_ID"].ToString()));
                if (_players.Count == currentNumPlayers && _players.Count >= 1)
                {
                    //Check if characters have changed
                    var newPlayerChars = new List <DataSet>
                    {
                        NetworkClasses.GetPlayer(int.Parse(ds.Tables[0].Rows[0]["Host"].ToString()))
                    };
                    for (var i = 2; i <= 6; i++)
                    {
                        if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["Player_" + i].ToString()))
                        {
                            newPlayerChars.Add(
                                NetworkClasses.GetPlayer(int.Parse(ds.Tables[0].Rows[0]["Player_" + i].ToString())));
                        }
                    }
                    for (var i = 0; i < newPlayerChars.Count; i++)
                    {
                        if (_players[i].Tables[0].Rows[0]["_Character"].ToString() !=
                            newPlayerChars[i].Tables[0].Rows[0]["_Character"].ToString())
                        {
                            done = false;
                            break;
                        }
                    }
                    if (done)
                    {
                        return;
                    }
                }

                //Updating
                _players.Clear();
                playerList.Items.Clear();
                var row = ds.Tables[0].Rows[0];

                var grabber = NetworkClasses.GetPlayer(int.Parse(row["Host"].ToString()));
                _players.Add(grabber);
                var Character = "";

                //Host
                var listItem = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                Character = grabber.Tables[0].Rows[0]["_Character"].ToString();
                listItem.SubItems.Add(Character);

                //Add the row entry to the listview
                playerList.Items.Add(listItem);

                for (var i = 2; i <= 6; i++)
                {
                    if (!string.IsNullOrEmpty(row["Player_" + i].ToString()))
                    {
                        grabber = NetworkClasses.GetPlayer(int.Parse(row["Player_" + i].ToString()));
                        _players.Add(grabber);
                        listItem  = new ListViewItem(grabber.Tables[0].Rows[0]["Username"].ToString());
                        Character = grabber.Tables[0].Rows[0]["_Character"].ToString();
                        listItem.SubItems.Add(Character);
                        playerList.Items.Add(listItem);
                    }
                }
            }
            catch (Exception e) //Thrown if server no longer exists
            {
                Console.WriteLine(e);
                //If the host leaves, the server no longer exists and the removing the player will throw an exception
                try
                {
                    NetworkClasses.FindRemovePlayer(Client.Conn, User.PlayerId);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                _chat.Dispose();
                Form form = new MainMenuForm();
                form.Show();
                _timer.Stop();
                Client.ClientStop();

                NetworkClasses.UpdateUserValue("User_List", "_Character", null, User.PlayerId);
                NetworkClasses.UpdateUserValue("User_List", "Online", "Online", User.PlayerId);
                Dispose();
                MessageBox.Show("Host left the game", "Server Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }