/// <summary>
        /// Initialize the form.
        /// </summary>
        private void Initialize()
        {
            //Initialize some components.
            InitializeComponent();

            //Initialize soma variables.
            _Profile = null;

            //Rename the controls' text.
            lblProfileName.Text = "Name:";
            txbProfileName.Text = "";
            btnAddProfile.Text = "Add Profile";
            btnFinish.Text = "Finish";

            //Add items to the combobox.
            foreach (Profile profile in Summary.Instance.Profiles) { cmbProfiles.Items.Add(profile); }
            cmbProfiles.SelectedIndex = (cmbProfiles.Items.Count > 0) ? 0 : cmbTeam.SelectedIndex;

            //Select the first profile in the list.
            SelectProfile(Summary.Instance.Profiles[0]);

            //Subscribe to events.
            cmbProfiles.SelectedIndexChanged += OnProfileChange;
            cmbTeam.SelectedIndexChanged += OnTeamChange;
            btnAddProfile.Click += OnAddProfileClick;
            btnFinish.Click += OnFinishClick;
        }
 /// <summary>
 /// If the user wants to add a profile.
 /// </summary>
 private void OnAddProfileClick(object sender, EventArgs e)
 {
     //Create a new profile and add him.
     Profile profile = new Profile("profile1", (Team)cmbTeam.SelectedItem);
     Summary.Instance.Profiles.Add(profile);
     //Add the profile to the combo box.
     cmbProfiles.Items.Add(profile);
 }
Esempio n. 3
0
        /// <summary>
        /// Initialize the form.
        /// </summary>
        /// <param name="profile">The profile that scored the goal.</param>
        public void Initialize(Profile profile)
        {
            //Initialize some components.
            InitializeComponent();

            //Initialize some variables.
            _Profile = profile;

            //Rename the controls' text.
            lblMinute.Text = "Minute:";
            btnFinish.Text = "Add the goal";
            txbMinute.Text = "0";

            //Add items to the comboboxes.
            foreach (Player player in _Profile.Team.Players) { cmbScorer.Items.Add(player); }
            cmbScorer.SelectedIndex = 0;

            cmbGoalType.Items.Add(GoalType.Shot);
            cmbGoalType.Items.Add(GoalType.Header);
            cmbGoalType.Items.Add(GoalType.Penalty);
            cmbGoalType.Items.Add(GoalType.Freekick);
            cmbGoalType.SelectedIndex = 0;
        }
Esempio n. 4
0
        /// <summary>
        /// Get the form curve of a profile.
        /// </summary>
        /// <param name="profile">The profile in question.</param>
        /// <param name="count">The number of games used.</param>
        /// <returns>The form curve.</returns>
        public string GetFormCurve(Profile profile, int count)
        {
            //The form curve.
            string form = "";
            //The number of games used.
            int index = 0;

            //Calculate the form curve.
            foreach (Game game in GetGames(profile))
            {
                //If enough games has been reviewed.
                if (index >= count) { break; }
                //Get the correct game facts.
                GameFacts facts = game.GetGameFacts(profile);

                //Check the result and write it down.
                if (facts.GoalsScored.Count > facts.GoalsConceded.Count) { form += "W"; }
                else if (facts.GoalsScored.Count < facts.GoalsConceded.Count) { form += "L"; }
                else if (facts.GoalsScored.Count == facts.GoalsConceded.Count) { form += "D"; }

                //Increment the index counter.
                index++;
            }

            //Return the form curve.
            return form;
        }
Esempio n. 5
0
 /// <summary>
 /// Create a game facts instance.
 /// </summary>
 /// <param name="profile">The profile.</param>
 public GameFacts(Profile profile)
 {
     Initialize(profile);
 }
Esempio n. 6
0
 /// <summary>
 /// Initialize the game facts.
 /// </summary>
 /// <param name="profile">The profile.</param>
 protected void Initialize(Profile profile)
 {
     //Initialize some stuff.
     _Profile = profile;
     _Team = null;
     _Bookings = new List<BookingType>();
     _GoalsScored = new List<Goal>();
     _GoalsConceded = new List<Goal>();
 }
Esempio n. 7
0
        /// <summary>
        /// Show and create a add goal form.
        /// </summary>
        /// <param name="profile">The profile that scored the goal.</param>
        private void ShowAddGoalForm(Profile profile)
        {
            //If there already is an add goal form open, do nothing.
            if (_AddGoalForm != null) { return; }

            //Create a form and show it to the user.
            _AddGoalForm = new AddGoal(profile);
            _AddGoalForm.Show();

            //Subscribe to its events.
            _AddGoalForm.Button.Click += OnbtnAddGoalFormClick;
            _AddGoalForm.FormClosing += OnAddGoalFormClose;
        }
Esempio n. 8
0
        /// <summary>
        /// Get the correct game facts instance.
        /// </summary>
        /// <param name="profile">The profile in question.</param>
        /// <returns>The game facts belonging to the specified profile.</returns>
        public GameFacts GetGameFacts(Profile profile)
        {
            //If the profile was the home team.
            if (_HomeFacts.Profile.Id == profile.Id) { return _HomeFacts; }
            else if (_AwayFacts.Profile.Id == profile.Id) { return _AwayFacts; }

            //Nothing happened.
            return null;
        }
Esempio n. 9
0
 /// <summary>
 /// Whether a certain profile participated in this game.
 /// </summary>
 /// <param name="profile">The profile in question.</param>
 /// <returns>True or false.</returns>
 public bool ContainsProfile(Profile profile)
 {
     return ((_HomeFacts.Profile.Id == profile.Id) || (_AwayFacts.Profile.Id == profile.Id));
 }
 /// <summary>
 /// Create a profile stat package.
 /// </summary>
 /// <param name="profile">The profile.</param>
 /// <param name="version">The FIFA version of the statistics.</param>
 public ProfileStatPackage(Profile profile, int version)
 {
     Initialize(profile, version);
 }
Esempio n. 11
0
        /// <summary>
        /// Load a profile, either from memory or file.
        /// </summary>
        /// <param name="id">The id of the profile.</param>
        /// <returns>The loaded profile.</returns>
        public static Profile LoadProfile(int id)
        {
            //In the all too likely event that everything inexplicably goes to hell.
            try
            {
                //Set up and load the xml file.
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(GetProfilePath(id));

                //Create the profile.
                Profile profile = new Profile(xmlDocument.SelectSingleNode("/Profile/Name").InnerText,
                    int.Parse(xmlDocument.SelectSingleNode("/Profile/Id").InnerText),
                    Summary.Instance.GetTeam(int.Parse(xmlDocument.SelectSingleNode("/Profile/Team").InnerText)));

                //The previous teams.
                foreach (XmlNode teamNode in xmlDocument.SelectNodes("Profile/Teams/Team"))
                {
                    //Load a team.
                    profile.PreviousTeams.Add(LoadTeam(int.Parse(teamNode.Attributes.GetNamedItem("Id").Value)));
                }

                //The statistics.
                foreach (XmlNode statNode in xmlDocument.SelectNodes("Profile/Statistics/StatPackage"))
                {
                    //Create the stat package.
                    ProfileStatPackage stats = new ProfileStatPackage(profile, int.Parse(statNode.Attributes.GetNamedItem("Version").Value));

                    //Parse the xml data.
                    stats.Games = int.Parse(statNode.SelectSingleNode("Games").InnerText);
                    stats.Points = int.Parse(statNode.SelectSingleNode("Points").InnerText);
                    stats.Wins = int.Parse(statNode.SelectSingleNode("Wins").InnerText);
                    stats.Draws = int.Parse(statNode.SelectSingleNode("Draws").InnerText);
                    stats.Losses = int.Parse(statNode.SelectSingleNode("Losses").InnerText);
                    stats.GoalsScored = int.Parse(statNode.SelectSingleNode("GoalsScored").InnerText);
                    stats.GoalsConceded = int.Parse(statNode.SelectSingleNode("GoalsConceded").InnerText);

                    //The scorers.
                    foreach (XmlNode scorerNode in statNode.SelectNodes("Scorers/Scorer"))
                    {
                        //Load a scorer.
                        stats.AddScorer(GetPlayer(scorerNode.Attributes.GetNamedItem("Id").Value),
                            int.Parse(scorerNode.Attributes.GetNamedItem("Goals").Value));
                    }

                    //Add the stat package.
                    profile.Statistics.Add(stats);
                }

                //Return the profile.
                return profile;
            }
            catch { return null; }
        }
Esempio n. 12
0
 /// <summary>
 /// Create the add goal form.
 /// </summary>
 /// <param name="profile">The profile that scored the goal.</param>
 public AddGoal(Profile profile)
 {
     //Initialize the form.
     Initialize(profile);
 }
        /// <summary>
        /// If the user is finished.
        /// </summary>
        private void OnFinishClick(object sender, EventArgs e)
        {
            //Save the modified profile name.
            if (_Profile != null) { _Profile.Name = txbProfileName.Text; }

            //Save the profile.
            Helper.SaveProfile(_Profile);

            //Let go of the profile.
            _Profile = null;

            //Close the form.
            this.Close();
        }
 /// <summary>
 /// Select a profile to edit.
 /// </summary>
 /// <param name="profile">The profile to edit.</param>
 private void SelectProfile(Profile profile)
 {
     //Perform the necessary arrangements.
     _Profile = profile;
     txbProfileName.Text = profile.Name;
     RefreshTeamList();
 }
Esempio n. 15
0
        /// <summary>
        /// Get the games that a particular profile was involved in, sorted by date in a ravashingly descending fashion.
        /// </summary>
        /// <param name="profile">The profile in question.</param>
        /// <returns>A list of games.</returns>
        public List<Game> GetGames(Profile profile)
        {
            //The games.
            List<Game> games = new List<Game>();

            //Add the games where the specified profile was involved to the list.
            foreach (Game game in _Games) { if (game.ContainsProfile(profile)) { games.Add(game); } }

            //Return the games; sorted by date.
            return games.OrderByDescending(g => g.Date).ToList<Game>();
        }
Esempio n. 16
0
        /// <summary>
        /// Save a profile to an xml file.
        /// </summary>
        /// <param name="profile">The profile to save.</param>
        public static void SaveProfile(Profile profile)
        {
            //Create the xml writer.
            XmlTextWriter textWriter = new XmlTextWriter(GetProfilePath(profile.Id), null);
            //Set the formatting to use indent.
            textWriter.Formatting = Formatting.Indented;

            //Begin with the profile.
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("Profile");
            {

                //The id.
                textWriter.WriteStartElement("Id");
                textWriter.WriteValue(profile.Id);
                textWriter.WriteEndElement();
                //The name.
                textWriter.WriteStartElement("Name");
                textWriter.WriteValue(profile.Name);
                textWriter.WriteEndElement();
                //The team.
                textWriter.WriteStartElement("Team");
                textWriter.WriteValue(profile.Team.Id);
                textWriter.WriteEndElement();

                //Begin with the list of teams.
                textWriter.WriteStartElement("Teams");
                textWriter.WriteAttributeString("Count", profile.PreviousTeams.Count.ToString());
                {

                    //The teams.
                    foreach (Team team in profile.PreviousTeams)
                    {
                        //Begin with a team.
                        textWriter.WriteStartElement("Team");
                        textWriter.WriteAttributeString("Id", team.Id.ToString());
                        textWriter.WriteEndElement();

                        //Save the team to the harddrive.
                        SaveTeam(team);
                    }

                }
                //End with the teams.
                textWriter.WriteEndElement();

                //Begin with the list of statistics.
                textWriter.WriteStartElement("Statistics");
                textWriter.WriteAttributeString("Count", profile.Statistics.Count.ToString());
                {

                    //The statistics.
                    foreach (ProfileStatPackage stats in profile.Statistics)
                    {
                        //Begin with a stat package.
                        textWriter.WriteStartElement("StatPackage");
                        textWriter.WriteAttributeString("Version", stats.Version.ToString());
                        {

                            //The games.
                            textWriter.WriteStartElement("Games");
                            textWriter.WriteValue(stats.Games);
                            textWriter.WriteEndElement();
                            //The points.
                            textWriter.WriteStartElement("Points");
                            textWriter.WriteValue(stats.Points);
                            textWriter.WriteEndElement();
                            //The wins.
                            textWriter.WriteStartElement("Wins");
                            textWriter.WriteValue(stats.Wins);
                            textWriter.WriteEndElement();
                            //The draws.
                            textWriter.WriteStartElement("Draws");
                            textWriter.WriteValue(stats.Draws);
                            textWriter.WriteEndElement();
                            //The losses.
                            textWriter.WriteStartElement("Losses");
                            textWriter.WriteValue(stats.Losses);
                            textWriter.WriteEndElement();
                            //The goals scored.
                            textWriter.WriteStartElement("GoalsScored");
                            textWriter.WriteValue(stats.GoalsScored);
                            textWriter.WriteEndElement();
                            //The goals conceded.
                            textWriter.WriteStartElement("GoalsConceded");
                            textWriter.WriteValue(stats.GoalsConceded);
                            textWriter.WriteEndElement();

                            //Begin with the list of scorers.
                            textWriter.WriteStartElement("Scorers");
                            textWriter.WriteAttributeString("Count", stats.Scorers.Count.ToString());
                            {

                                //The top scorers.
                                foreach (KeyValuePair<Player, int> pair in stats.Scorers)
                                {
                                    //Begin with a scorer.
                                    textWriter.WriteStartElement("Scorer");
                                    textWriter.WriteAttributeString("Id", pair.Key.Team.Id.ToString() + ":" + pair.Key.Name);
                                    textWriter.WriteAttributeString("Goals", pair.Value.ToString());
                                    textWriter.WriteEndElement();
                                }

                            }
                            //End with the scorers.
                            textWriter.WriteEndElement();

                        }
                        //End the stat package.
                        textWriter.WriteEndElement();
                    }
                }
                //End with the statistics.
                textWriter.WriteEndElement();

            }
            //End with the profile.
            textWriter.WriteEndElement();

            //End with the document.
            textWriter.WriteEndDocument();
            //Close the writer.
            textWriter.Close();
        }
Esempio n. 17
0
 /// <summary>
 /// Give the profile some id.
 /// </summary>
 /// <param name="profile">The profile in question.</param>
 public void GrantProfileId(Profile profile)
 {
     //Increment the counter.
     _LastProfileId++;
     //Give the profile some id.
     profile.Id = _LastProfileId;
 }
 /// <summary>
 /// Initialize the profile.
 /// </summary>
 /// <param name="profile">The profile.</param>
 /// <param name="version">The FIFA version of the statistics.</param>
 private void Initialize(Profile profile, int version)
 {
     //Initialize some values.
     _Profile = profile;
     _Version = version;
     _Games = 0;
     _Wins = 0;
     _Draws = 0;
     _Losses = 0;
     _Points = 0;
     _GoalsScored = 0;
     _GoalsConceded = 0;
     _Scorers = new Dictionary<Player, int>();
 }