Ejemplo n.º 1
0
        /// <summary>
        /// When the button has been clicked.
        /// </summary>
        /// <param name="o"></param>
        /// <param name="e"></param>
        private void OnbtnAddGoalFormClick(object o, EventArgs e)
        {
            //Create a goal with the form's data and add it to the game.
            Goal goal = new Goal();
            goal.Scorer = _AddGoalForm.Scorer;
            goal.Minute = _AddGoalForm.Minute;
            goal.Type = _AddGoalForm.GoalType;

            //Find out where to accredit the goal.
            ListViewItem item = new ListViewItem(goal.ToString());
            item.Tag = goal;

            if (_AddGoalForm.Profile == (Profile)cmbHomeProfile.SelectedItem) { lstvHomeGoals.Items.Add(item); }
            else if (_AddGoalForm.Profile == (Profile)cmbAwayProfile.SelectedItem) { lstvAwayGoals.Items.Add(item); }

            //Update the result labels.
            lblHomeGoals.Text = lstvHomeGoals.Items.Count.ToString();
            lblAwayGoals.Text = lstvAwayGoals.Items.Count.ToString();

            //Close the form.
            _AddGoalForm.Close();
        }
Ejemplo n.º 2
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; }
        }