/// <summary>
        /// Whether a list contains a specific player. The method tries to match the players' ids rather than reference.
        /// </summary>
        /// <param name="players">The list of players.</param>
        /// <param name="player">The player to try and find.</param>
        /// <returns>The player that matched.</returns>
        public static Player ContainsPlayer(List<Player> players, Player player)
        {
            //For all players in the list, check for a match.
            foreach (Player p in players) { if (player.Name.Equals(p.Name) && player.Team.Id.ToString().Equals(p.Team.Id.ToString())) { return p; } }

            //No player found.
            return null;
        }
 /// <summary>
 /// If the user wants to add a player to a team.
 /// </summary>
 private void OnAddPlayerClick(object sender, EventArgs e)
 {
     //Create a new player and add him to the team.
     Player player = new Player("player1", _Team);
     _Team.Players.Add(player);
     //Add the player to the list box.
     lstbPlayers.Items.Add(player);
 }
        /// <summary>
        /// Initialize the form.
        /// </summary>
        private void Initialize()
        {
            //Initialize some components.
            InitializeComponent();

            //Initialize some variables.
            _Team = null;
            _Player = null;

            //Make the edit controls invisible.
            grpbEditPlayer.Visible = false;
            lblPlayerName.Visible = false;
            txbPlayerName.Visible = false;

            //Rename the controls' text.
            lblTeamName.Text = "Name:";
            grpbEditPlayer.Text = "Edit Player";
            lblPlayers.Text = "The players";
            lblPlayerName.Text = "Player:";
            txbTeamName.Text = (_Team != null) ? _Team.Name : "";
            txbPlayerName.Text = "";
            btnAddPlayer.Text = "Add Player";
            btnAddTeam.Text = "Add Team";
            btnFinish.Text = "Finish";

            //Add items to the combobox.
            foreach (Team team in Summary.Instance.Teams) { cmbTeams.Items.Add(team); }
            cmbTeams.SelectedIndex = 0;

            //Select the first team in the list.
            SelectTeam(Summary.Instance.Teams[0]);

            //Select the first player in the list.
            lstbPlayers.SelectedIndex = (lstbPlayers.Items.Count > 0) ? 0 : -1;

            //Subscribe to events. NOTE: The lstbPlayer selection event is managed in the RefreshPlayerList method.
            cmbTeams.SelectedIndexChanged += OnTeamChange;
            btnAddPlayer.Click += OnAddPlayerClick;
            btnAddTeam.Click += OnAddTeamClick;
            btnFinish.Click += OnFinishClick;
        }
        /// <summary>
        /// Add a goalscorer.
        /// </summary>
        /// <param name="version">The FIFA version.</param>
        /// <param name="player">The player that has scored.</param>
        /// <param name="goals">The number of goals scored since last update.</param>
        public void AddScorer(int version, Player player, int goals)
        {
            //Find the correct stat package.
            ProfileStatPackage stats = GetStatPackage(version);

            //If not null, try to add the goal scorer to it.
            if (stats != null) { stats.AddScorer(player, goals); }
        }
 /// <summary>
 /// Add a goal to a player.
 /// </summary>
 /// <param name="version">The FIFA version.</param>
 /// <param name="player">The player that scored.</param>
 public void AddScorer(int version, Player player)
 {
     AddScorer(version, player, 1);
 }
 /// <summary>
 /// Give the player some id.
 /// </summary>
 /// <param name="player">The player in question.</param>
 public void GrantPlayerId(Player player)
 {
     //Increment the counter.
     _LastPlayerId++;
     //Give the game some id.
     player.Id = _LastPlayerId;
 }
        /// <summary>
        /// Select a player to edit.
        /// </summary>
        /// <param name="player">The player to edit.</param>
        private void SelectPlayer(Player player)
        {
            //Save the modified player name.
            if (_Player != null) { _Player.Name = txbPlayerName.Text; }

            //Perform the necessary arrangements.
            _Player = player;
            RefreshPlayerList();

            if (_Player != null)
            {
                //Enable modification of the player's name.
                txbPlayerName.Text = _Player.Name;

                //Make the edit controls visible.
                grpbEditPlayer.Visible = true;
                lblPlayerName.Visible = true;
                txbPlayerName.Visible = true;
            }
            else
            {
                //Make the edit controls invisible.
                grpbEditPlayer.Visible = false;
                lblPlayerName.Visible = false;
                txbPlayerName.Visible = false;
            }
        }
        /// <summary>
        /// If the user is finished.
        /// </summary>
        private void OnFinishClick(object sender, EventArgs e)
        {
            //Save the modified team and player name.
            if (_Team != null) { _Team.Name = txbTeamName.Text; }
            if (_Player != null) { _Player.Name = txbPlayerName.Text; }

            //Save the team.
            Helper.SaveTeam(_Team);

            //Tell the summary to reload the profiles.
            Summary.Instance.LoadAllProfiles();

            //Let go of the player and the team.
            _Team = null;
            _Player = null;

            //Close the form.
            this.Close();
        }
        /// <summary>
        /// Save a player to an xml file.
        /// </summary>
        /// <param name="player">The player to save.</param>
        public static void SavePlayer(Player player)
        {
            //Create the xml writer.
            XmlTextWriter textWriter = new XmlTextWriter("", null);
            //Set the formatting to use indent.
            textWriter.Formatting = Formatting.Indented;

            //Begin with the player.
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("Summary");

            //The last profile id.
            textWriter.WriteStartElement("LastProfileId");
            //textWriter.WriteValue(player.LastProfileId);
            textWriter.WriteEndElement();
            //The last team id.
            textWriter.WriteStartElement("LastTeamId");
            //textWriter.WriteValue(player.LastTeamId);
            textWriter.WriteEndElement();
            //The last game id.
            textWriter.WriteStartElement("LastGameId");
            //textWriter.WriteValue(player.LastGameId);
            textWriter.WriteEndElement();

            //End with the summary.
            textWriter.WriteEndElement();

            //End with the document.
            textWriter.WriteEndDocument();
            //Close the writer.
            textWriter.Close();
        }
        /// <summary>
        /// Add a goalscorer.
        /// </summary>
        /// <param name="player">The player that has scored.</param>
        /// <param name="goals">The number of goals scored since last update.</param>
        public void AddScorer(Player player, int goals)
        {
            //If the input is not valid, stop here.
            if (player == null || goals < 0) { return; }

            //Try to find a source instance of the same player.
            Player source = Helper.ContainsPlayer(_Scorers.Keys.ToList(), player);

            //See if the player already exists in the list.
            if (source != null)
            {
                //Increment the player's number of goals.
                _Scorers[source] += goals;
            }
            //Else, create a new entry.
            else { _Scorers.Add(player, goals); }

            //Sort the dictionary.
            SortTopScorers();
        }