Exemplo n.º 1
0
        /// <summary>
        /// Add a game to this profile. If the profile did not play the game, the game will be ignored.
        /// </summary>
        /// <param name="game">The game to add.</param>
        public void AddGame(Game game)
        {
            //Find the correct stat package.
            ProfileStatPackage stats = GetStatPackage(game.FIFAVersion);

            //If not null, try to add the game to it. Otherwise create a new stat package entry.
            if (stats != null) { stats.AddGame(game); }
            else
            {
                _Statistics.Add(new ProfileStatPackage(this, game.FIFAVersion));
                _Statistics[_Statistics.Count - 1].AddGame(game);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Give the game some id.
 /// </summary>
 /// <param name="game">The game in question.</param>
 public void GrantGameId(Game game)
 {
     //Increment the counter.
     _LastGameId++;
     //Give the game some id.
     game.Id = _LastGameId;
 }
Exemplo n.º 3
0
        /// <summary>
        /// If the user is finished.
        /// </summary>
        private void OnFinishClick(object sender, EventArgs e)
        {
            //Create a game with the form's data and save it.
            Game game = new Game();
            game.ExtraTime = ckbExtraTime.Checked;
            game.HomeFacts = GetGameFacts(MatchSide.Home);
            game.AwayFacts = GetGameFacts(MatchSide.Away);
            Helper.SaveGame(game);

            //Add the game to the profiles and save them.
            game.HomeFacts.Profile.AddGame(game);
            game.AwayFacts.Profile.AddGame(game);
            Helper.SaveProfile(game.HomeFacts.Profile);
            Helper.SaveProfile(game.AwayFacts.Profile);

            //Add the game to the list.
            Summary.Instance.Games.Add(game);

            //Close the form.
            this.Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Load a game.
        /// </summary>
        /// <param name="id">The id of the game to load.</param>
        /// <returns>The loaded game.</returns>
        public static Game LoadGame(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(GetGamePath(id));

                //Create the game.
                Game game = new Game(int.Parse(xmlDocument.SelectSingleNode("/Game/Id").InnerText));

                //Parse the xml data.
                game.FIFAVersion = int.Parse(xmlDocument.SelectSingleNode("/Game/FIFAVersion").InnerText);
                game.Date = DateTime.Parse(xmlDocument.SelectSingleNode("/Game/Date").InnerText);
                game.ExtraTime = bool.Parse(xmlDocument.SelectSingleNode("/Game/ExtraTime").InnerText);

                #region HomeFacts
                //The home facts.
                game.HomeFacts = new GameFacts(LoadProfile(int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/Profile").InnerText)));

                //Parse the xml data.
                game.HomeFacts.Team = LoadTeam(int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/Team").InnerText));
                game.HomeFacts.MatchSide = (MatchSide)Enum.Parse(typeof(MatchSide), xmlDocument.SelectSingleNode("/Game/HomeFacts/MatchSide").InnerText);
                game.HomeFacts.Shots = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/Shots").InnerText);
                game.HomeFacts.ShotsOnTarget = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/ShotsOnTarget").InnerText);
                game.HomeFacts.ShotAccuracy = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/ShotAccuracy").InnerText);
                game.HomeFacts.PassAccuracy = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/PassAccuracy").InnerText);
                game.HomeFacts.Corners = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/Corners").InnerText);
                game.HomeFacts.Possession = int.Parse(xmlDocument.SelectSingleNode("/Game/HomeFacts/Possession").InnerText);

                //The goals scored.
                foreach (XmlNode scoredNode in xmlDocument.SelectNodes("/Game/HomeFacts/GoalsScored/Goal"))
                {
                    //Create a goal.
                    Goal goal = new Goal();

                    //Parse the xml data.
                    goal.Scorer = GetPlayer(scoredNode.SelectSingleNode("Scorer").InnerText);
                    goal.Minute = int.Parse(scoredNode.SelectSingleNode("Minute").InnerText);
                    goal.Type = (GoalType)Enum.Parse(typeof(GoalType), scoredNode.SelectSingleNode("Type").InnerText);

                    //Add the goal to the home facts.
                    game.HomeFacts.GoalsScored.Add(goal);
                }

                //The goals conceded.
                foreach (XmlNode concededNode in xmlDocument.SelectNodes("/Game/HomeFacts/GoalsConceded/Goal"))
                {
                    //Create a goal.
                    Goal goal = new Goal();

                    //Parse the xml data.
                    goal.Scorer = GetPlayer(concededNode.SelectSingleNode("Scorer").InnerText);
                    goal.Minute = int.Parse(concededNode.SelectSingleNode("Minute").InnerText);
                    goal.Type = (GoalType)Enum.Parse(typeof(GoalType), concededNode.SelectSingleNode("Type").InnerText);

                    //Add the goal to the home facts.
                    game.HomeFacts.GoalsConceded.Add(goal);
                }

                //The bookings.
                foreach (XmlNode bookingNode in xmlDocument.SelectNodes("/Game/HomeFacts/Bookings/Booking"))
                {
                    //Parse the xml data.
                    //game.HomeFacts.Bookings.Add((BookingType)Enum.Parse(typeof(BookingType), bookingNode.SelectSingleNode("Booking").InnerText));
                }
                #endregion

                #region AwayFacts
                //The away facts.
                game.AwayFacts = new GameFacts(LoadProfile(int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/Profile").InnerText)));

                //Parse the xml data.
                game.AwayFacts.Team = LoadTeam(int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/Team").InnerText));
                game.AwayFacts.MatchSide = (MatchSide)Enum.Parse(typeof(MatchSide), xmlDocument.SelectSingleNode("/Game/AwayFacts/MatchSide").InnerText);
                game.AwayFacts.Shots = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/Shots").InnerText);
                game.AwayFacts.ShotsOnTarget = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/ShotsOnTarget").InnerText);
                game.AwayFacts.ShotAccuracy = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/ShotAccuracy").InnerText);
                game.AwayFacts.PassAccuracy = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/PassAccuracy").InnerText);
                game.AwayFacts.Corners = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/Corners").InnerText);
                game.AwayFacts.Possession = int.Parse(xmlDocument.SelectSingleNode("/Game/AwayFacts/Possession").InnerText);

                //The goals scored.
                foreach (XmlNode scoredNode in xmlDocument.SelectNodes("/Game/AwayFacts/GoalsScored/Goal"))
                {
                    //Create a goal.
                    Goal goal = new Goal();

                    //Parse the xml data.
                    goal.Scorer = GetPlayer(scoredNode.SelectSingleNode("Scorer").InnerText);
                    goal.Minute = int.Parse(scoredNode.SelectSingleNode("Minute").InnerText);
                    goal.Type = (GoalType)Enum.Parse(typeof(GoalType), scoredNode.SelectSingleNode("Type").InnerText);

                    //Add the goal to the home facts.
                    game.AwayFacts.GoalsScored.Add(goal);
                }

                //The goals conceded.
                foreach (XmlNode concededNode in xmlDocument.SelectNodes("/Game/AwayFacts/GoalsConceded/Goal"))
                {
                    //Create a goal.
                    Goal goal = new Goal();

                    //Parse the xml data.
                    goal.Scorer = GetPlayer(concededNode.SelectSingleNode("Scorer").InnerText);
                    goal.Minute = int.Parse(concededNode.SelectSingleNode("Minute").InnerText);
                    goal.Type = (GoalType)Enum.Parse(typeof(GoalType), concededNode.SelectSingleNode("Type").InnerText);

                    //Add the goal to the home facts.
                    game.AwayFacts.GoalsConceded.Add(goal);
                }

                //The bookings.
                foreach (XmlNode bookingNode in xmlDocument.SelectNodes("Bookings/Booking"))
                {
                    //Parse the xml data.
                    //game.AwayFacts.Bookings.Add((BookingType)Enum.Parse(typeof(BookingType), bookingNode.SelectSingleNode("Booking").InnerText));
                }
                #endregion

                //Return the game.
                return game;
            }
            catch { return null; }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Save a game to an xml file.
        /// </summary>
        /// <param name="game">The game to save.</param>
        public static void SaveGame(Game game)
        {
            //Create the xml writer.
            XmlTextWriter textWriter = new XmlTextWriter(GetGamePath(game.Id), null);
            //Set the formatting to use indent.
            textWriter.Formatting = Formatting.Indented;

            //Begin with the game.
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("Game");

            //The id.
            textWriter.WriteStartElement("Id");
            textWriter.WriteValue(game.Id);
            textWriter.WriteEndElement();
            //The FIFA version.
            textWriter.WriteStartElement("FIFAVersion");
            textWriter.WriteValue(game.FIFAVersion);
            textWriter.WriteEndElement();
            //The date.
            textWriter.WriteStartElement("Date");
            textWriter.WriteString(game.Date.ToString());
            textWriter.WriteEndElement();
            //The extra time.
            textWriter.WriteStartElement("ExtraTime");
            textWriter.WriteValue(game.ExtraTime);
            textWriter.WriteEndElement();

            #region HomeFacts
            //Begin with the home game facts.
            textWriter.WriteStartElement("HomeFacts");

            //The profile.
            textWriter.WriteStartElement("Profile");
            textWriter.WriteValue(game.HomeFacts.Profile.Id);
            textWriter.WriteEndElement();
            //The team.
            textWriter.WriteStartElement("Team");
            textWriter.WriteValue(game.HomeFacts.Team.Id);
            textWriter.WriteEndElement();
            //The match side.
            textWriter.WriteStartElement("MatchSide");
            textWriter.WriteString(game.HomeFacts.MatchSide.ToString());
            textWriter.WriteEndElement();
            //The number of shots.
            textWriter.WriteStartElement("Shots");
            textWriter.WriteValue(game.HomeFacts.Shots);
            textWriter.WriteEndElement();
            //The number of shots on target.
            textWriter.WriteStartElement("ShotsOnTarget");
            textWriter.WriteValue(game.HomeFacts.ShotsOnTarget);
            textWriter.WriteEndElement();
            //The shot accuracy.
            textWriter.WriteStartElement("ShotAccuracy");
            textWriter.WriteValue(game.HomeFacts.ShotAccuracy);
            textWriter.WriteEndElement();
            //The pass accuracy.
            textWriter.WriteStartElement("PassAccuracy");
            textWriter.WriteValue(game.HomeFacts.PassAccuracy);
            textWriter.WriteEndElement();
            //The number of corners.
            textWriter.WriteStartElement("Corners");
            textWriter.WriteValue(game.HomeFacts.Corners);
            textWriter.WriteEndElement();
            //The amount of possession.
            textWriter.WriteStartElement("Possession");
            textWriter.WriteValue(game.HomeFacts.Possession);
            textWriter.WriteEndElement();

            //Begin with the goals scored.
            textWriter.WriteStartElement("GoalsScored");
            textWriter.WriteAttributeString("Count", game.HomeFacts.GoalsScored.Count.ToString());

            //The goals scored.
            foreach (Goal goal in game.HomeFacts.GoalsScored)
            {
                //Begin with a goal.
                textWriter.WriteStartElement("Goal");

                //The player who scored.
                textWriter.WriteStartElement("Scorer");
                textWriter.WriteString(goal.Scorer.Team.Id.ToString() + ":" + goal.Scorer.Name);
                textWriter.WriteEndElement();
                //The time of the goal.
                textWriter.WriteStartElement("Minute");
                textWriter.WriteValue(goal.Minute.ToString());
                textWriter.WriteEndElement();
                //The type of goal.
                textWriter.WriteStartElement("Type");
                textWriter.WriteString(goal.Type.ToString());
                textWriter.WriteEndElement();

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

            //End with the goals scored.
            textWriter.WriteEndElement();

            //Begin with the goals conceded.
            textWriter.WriteStartElement("GoalsConceded");
            textWriter.WriteAttributeString("Count", game.HomeFacts.GoalsConceded.Count.ToString());

            //The goals conceded.
            foreach (Goal goal in game.HomeFacts.GoalsConceded)
            {
                //Begin with a goal.
                textWriter.WriteStartElement("Goal");

                //The player who scored.
                textWriter.WriteStartElement("Scorer");
                textWriter.WriteString(goal.Scorer.Team.Id.ToString() + ":" + goal.Scorer.Name);
                textWriter.WriteEndElement();
                //The time of the goal.
                textWriter.WriteStartElement("Minute");
                textWriter.WriteString(goal.Minute.ToString());
                textWriter.WriteEndElement();
                //The type of goal.
                textWriter.WriteStartElement("Type");
                textWriter.WriteString(goal.Type.ToString());
                textWriter.WriteEndElement();

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

            //End with the goals conceded.
            textWriter.WriteEndElement();

            //Begin with the bookings.
            textWriter.WriteStartElement("Bookings");
            textWriter.WriteAttributeString("Count", game.HomeFacts.Bookings.Count.ToString());

            //The bookings.
            foreach (BookingType booking in game.HomeFacts.Bookings)
            {
                //A booking.
                textWriter.WriteStartElement("Booking");
                textWriter.WriteString(booking.ToString());
                textWriter.WriteEndElement();
            }

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

            //End with the home game facts.
            textWriter.WriteEndElement();
            #endregion

            #region AwayFacts
            //Begin with the away game facts.
            textWriter.WriteStartElement("AwayFacts");

            //The profile.
            textWriter.WriteStartElement("Profile");
            textWriter.WriteValue(game.AwayFacts.Profile.Id);
            textWriter.WriteEndElement();
            //The team.
            textWriter.WriteStartElement("Team");
            textWriter.WriteValue(game.AwayFacts.Team.Id);
            textWriter.WriteEndElement();
            //The match side.
            textWriter.WriteStartElement("MatchSide");
            textWriter.WriteString(game.AwayFacts.MatchSide.ToString());
            textWriter.WriteEndElement();
            //The number of shots.
            textWriter.WriteStartElement("Shots");
            textWriter.WriteValue(game.AwayFacts.Shots);
            textWriter.WriteEndElement();
            //The number of shots on target.
            textWriter.WriteStartElement("ShotsOnTarget");
            textWriter.WriteValue(game.AwayFacts.ShotsOnTarget);
            textWriter.WriteEndElement();
            //The shot accuracy.
            textWriter.WriteStartElement("ShotAccuracy");
            textWriter.WriteValue(game.AwayFacts.ShotAccuracy);
            textWriter.WriteEndElement();
            //The pass accuracy.
            textWriter.WriteStartElement("PassAccuracy");
            textWriter.WriteValue(game.AwayFacts.PassAccuracy);
            textWriter.WriteEndElement();
            //The number of corners.
            textWriter.WriteStartElement("Corners");
            textWriter.WriteValue(game.AwayFacts.Corners);
            textWriter.WriteEndElement();
            //The amount of possession.
            textWriter.WriteStartElement("Possession");
            textWriter.WriteValue(game.AwayFacts.Possession);
            textWriter.WriteEndElement();

            //Begin with the goals scored.
            textWriter.WriteStartElement("GoalsScored");
            textWriter.WriteAttributeString("Count", game.AwayFacts.GoalsScored.Count.ToString());

            //The goals scored.
            foreach (Goal goal in game.AwayFacts.GoalsScored)
            {
                //Begin with a goal.
                textWriter.WriteStartElement("Goal");

                //The player who scored.
                textWriter.WriteStartElement("Scorer");
                textWriter.WriteString(goal.Scorer.Team.Id.ToString() + ":" + goal.Scorer.Name);
                textWriter.WriteEndElement();
                //The time of the goal.
                textWriter.WriteStartElement("Minute");
                textWriter.WriteValue(goal.Minute);
                textWriter.WriteEndElement();
                //The type of goal.
                textWriter.WriteStartElement("Type");
                textWriter.WriteString(goal.Type.ToString());
                textWriter.WriteEndElement();

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

            //End with the goals scored.
            textWriter.WriteEndElement();

            //Begin with the goals conceded.
            textWriter.WriteStartElement("GoalsConceded");
            textWriter.WriteAttributeString("Count", game.AwayFacts.GoalsConceded.Count.ToString());

            //The goals conceded.
            foreach (Goal goal in game.AwayFacts.GoalsConceded)
            {
                //Begin with a goal.
                textWriter.WriteStartElement("Goal");

                //The player who scored.
                textWriter.WriteStartElement("Scorer");
                textWriter.WriteString(goal.Scorer.Team.Id.ToString() + ":" + goal.Scorer.Name);
                textWriter.WriteEndElement();
                //The time of the goal.
                textWriter.WriteStartElement("Minute");
                textWriter.WriteString(goal.Minute.ToString());
                textWriter.WriteEndElement();
                //The type of goal.
                textWriter.WriteStartElement("Type");
                textWriter.WriteString(goal.Type.ToString());
                textWriter.WriteEndElement();

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

            //End with the goals conceded.
            textWriter.WriteEndElement();

            //Begin with the bookings.
            textWriter.WriteStartElement("Bookings");
            textWriter.WriteAttributeString("Count", game.AwayFacts.Bookings.Count.ToString());

            //The bookings.
            foreach (BookingType booking in game.AwayFacts.Bookings)
            {
                //A booking.
                textWriter.WriteStartElement("Booking");
                textWriter.WriteString(booking.ToString());
                textWriter.WriteEndElement();
            }

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

            //End with the away game facts.
            textWriter.WriteEndElement();
            #endregion

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

            //End with the document.
            textWriter.WriteEndDocument();
            //Close the writer.
            textWriter.Close();
        }
        /// <summary>
        /// Add a game to this profile statistics package. If the profile did not play the game or if the FIFA versions do not match, the game will be ignored.
        /// </summary>
        /// <param name="game">The game to add.</param>
        public void AddGame(Game game)
        {
            //If the game's FIFA version does not match the package's, stop here.
            if (game.FIFAVersion != _Version) { return; }

            //The game facts to use.
            GameFacts facts = null;

            //See what side the profile was on.
            if (game.HomeFacts.Profile.Id == _Profile.Id) { facts = game.HomeFacts; }
            else if (game.AwayFacts.Profile.Id == _Profile.Id) { facts = game.AwayFacts; }
            else { return; }

            //Add the data to the profile.
            _Games += 1;
            _Wins += (facts.GoalsScored.Count > facts.GoalsConceded.Count) ? 1 : 0;
            _Draws += (facts.GoalsScored.Count == facts.GoalsConceded.Count) ? 1 : 0;
            _Losses += (facts.GoalsScored.Count < facts.GoalsConceded.Count) ? 1 : 0;
            _GoalsScored += facts.GoalsScored.Count;
            _GoalsConceded += facts.GoalsConceded.Count;

            //For every player in this profile's team that scored, increment his tally.
            foreach (Goal goal in facts.GoalsScored) { AddScorer(goal.Scorer, 1); }

            //Add points.
            if (game.ExtraTime)
            {
                //Win.
                if (facts.GoalsScored.Count > facts.GoalsConceded.Count) { _Points += 2; }
                //Loss.
                if (facts.GoalsScored.Count < facts.GoalsConceded.Count) { _Points += 1; }
            }
            else
            {
                //Win.
                if (facts.GoalsScored.Count > facts.GoalsConceded.Count) { _Points += 3; }
            }
        }