예제 #1
0
        /// <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;
        }
예제 #2
0
 /// <summary>
 /// Create a profile.
 /// </summary>
 /// <param name="name">The name of the profile.</param>
 /// <param name="id">The id of this profile.</param>
 /// <param name="team">The team that this profile uses.</param>
 public Profile(string name, int id, Team team)
 {
     Initialize(name, id, team);
 }
예제 #3
0
 /// <summary>
 /// Create a profile.
 /// </summary>
 /// <param name="name">The name of the profile.</param>
 /// <param name="team">The team that this profile uses.</param>
 public Profile(string name, Team team)
 {
     Initialize(name, -1, team);
 }
예제 #4
0
        /// <summary>
        /// Initialize the profile.
        /// </summary>
        /// <param name="name">The name of this profile.</param>
        /// <param name="id">The id of this profile.</param>
        /// <param name="team">The team that this profile uses.</param>
        private void Initialize(string name, int id, Team team)
        {
            //Initialize some values.
            _Name = name;
            _Id = id;
            _Teams = new List<Team>();
            _Teams.Add(team);
            _Statistics = new List<ProfileStatPackage>();

            //Get an id.
            if (_Id == -1) { Summary.Instance.GrantProfileId(this); }
        }
예제 #5
0
 /// <summary>
 /// Give the team some id.
 /// </summary>
 /// <param name="team">The team in question.</param>
 public void GrantTeamId(Team team)
 {
     //Increment the counter.
     _LastTeamId++;
     //Give the team some id.
     team.Id = _LastTeamId;
 }
예제 #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>();
 }
예제 #7
0
 /// <summary>
 /// If the user wants to add a team.
 /// </summary>
 private void OnAddTeamClick(object sender, EventArgs e)
 {
     //Create a new team and add him.
     Team team = new Team("team1");
     Summary.Instance.Teams.Add(team);
     //Add the team to the combo box.
     cmbTeams.Items.Add(team);
     //Select the team.
     cmbTeams.SelectedIndex = cmbTeams.Items.Count - 1;
 }
예제 #8
0
        /// <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();
        }
예제 #9
0
 /// <summary>
 /// Select a team to edit.
 /// </summary>
 /// <param name="team">The team to edit.</param>
 private void SelectTeam(Team team)
 {
     //Perform the necessary arrangements.
     _Team = team;
     txbTeamName.Text = team.Name;
     RefreshPlayerList();
 }
예제 #10
0
 /// <summary>
 /// Initialize the player.
 /// </summary>
 /// <param name="name">The name of the player.</param>
 /// <param name="id">The id of the player.</param>
 /// <param name="team">The team that the player belongs to.</param>
 protected void Initialize(string name, int id, Team team)
 {
     //Initialize some stuff.
     _Name = name;
     _Id = id;
     _Team = team;
 }
예제 #11
0
 /// <summary>
 /// Create a player.
 /// </summary>
 /// <param name="name">The name of the player.</param>
 /// <param name="id">The id of the player.</param>
 /// <param name="team">The team that the player belongs to.</param>
 public Player(string name, int id, Team team)
 {
     Initialize(name, id, team);
 }
예제 #12
0
 /// <summary>
 /// Create a player.
 /// </summary>
 /// <param name="name">The name of the player.</param>
 /// <param name="team">The team that the player belongs to.</param>
 public Player(string name, Team team)
 {
     Initialize(name, -1, team);
 }
예제 #13
0
        /// <summary>
        /// Save a team to an xml file.
        /// </summary>
        /// <param name="team">The team to save.</param>
        public static void SaveTeam(Team team)
        {
            //Create the xml writer.
            XmlTextWriter textWriter = new XmlTextWriter(GetTeamPath(team.Id), null);
            //Set the formatting to use indent.
            textWriter.Formatting = Formatting.Indented;

            //Begin with the team.
            textWriter.WriteStartDocument();
            textWriter.WriteStartElement("Team");
            textWriter.WriteAttributeString("Id", team.Id.ToString());
            textWriter.WriteAttributeString("Name", team.Name);

            //Begin with the players.
            textWriter.WriteStartElement("Players");
            textWriter.WriteAttributeString("Count", team.Players.Count.ToString());

            //The players.
            foreach (Player player in team.Players)
            {
                //Begin with a player.
                textWriter.WriteStartElement("Player");
                textWriter.WriteAttributeString("Name", player.Name);
                textWriter.WriteEndElement();
            }

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

            //End with the document.
            textWriter.WriteEndDocument();
            //Close the writer.
            textWriter.Close();
        }
예제 #14
0
        /// <summary>
        /// Load a team.
        /// </summary>
        /// <param name="id">The path to the team's file.</param>
        /// <returns>The loaded team.</returns>
        public static Team LoadTeam(string path)
        {
            //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(path);

                //Create the team.
                Team team = new Team(xmlDocument.GetElementsByTagName("Team")[0].Attributes[1].Value,
                    int.Parse(xmlDocument.GetElementsByTagName("Team")[0].Attributes[0].Value));

                //The players.
                foreach (XmlNode playerNode in xmlDocument.SelectNodes("Team/Players/Player"))
                {
                    //Create a player.
                    team.Players.Add(new Player(playerNode.Attributes.GetNamedItem("Name").Value, team));
                }

                //Return the team.
                return team;
            }
            catch { return null; }
        }