public void AddPlayer(MatchPlayer mp) { List<MatchPlayer> newPlayers = new List<MatchPlayer>(); newPlayers.AddRange(this.Players); newPlayers.Add(mp); this.Players = newPlayers.ToArray(); }
private void addPlayerButton_Click(object sender, EventArgs e) { Button addButton = (Button)sender; ComboBox playerSelect; TextBox tossupBox; TextBox durBox; ListView listView; Button removeButton; MatchTeam team; if (addButton == addPlayerButton1) { playerSelect = playerBox1; tossupBox = tossupBox1; durBox = durationBox1; listView = playerListView1; team = this.thisMatch.FirstTeam; removeButton = removePlayerButton1; } else { playerSelect = playerBox2; tossupBox = tossupBox2; durBox = durationBox2; listView = playerListView2; team = this.thisMatch.SecondTeam; removeButton = removePlayerButton2; } if (playerSelect.SelectedIndex == -1) { toolTip1.ToolTipTitle = "No Player Selected!"; toolTip1.Show("You have selected a player for these statistics to be applied.", playerSelect); return; } if (tossupBox.Text.Equals("")) { toolTip1.ToolTipTitle = "No Tossups Entered!"; toolTip1.Show("You have not entered any tossups for this player.", tossupBox); return; } if (durBox.Text.Equals("")) { toolTip1.ToolTipTitle = "No Durration Entered!"; toolTip1.Show("You have not entered the duration for which this player played.", durBox); return; } MatchPlayer player; if ((player = team.FindPlayer(playerSelect.SelectedItem.ToString())) == null) { player = new MatchPlayer( MainForm.Players[playerSelect.SelectedItem.ToString()], decimal.Parse(tossupBox.Text), decimal.Parse(durBox.Text)); team.AddPlayer(player); ListViewItem item = new ListViewItem(); item.Text = player.Name; item.SubItems.Add(player.Tossups.ToString()); item.SubItems.Add(player.Duration.ToString()); listView.Items.Add(item); addButton.Text = "Set Player"; removeButton.Enabled = true; } else { player.Tossups = decimal.Parse(tossupBox.Text); player.Duration = decimal.Parse(durBox.Text); foreach (ListViewItem item in listView.Items) { if (item.Text.Equals(player.Name)) { item.SubItems[1].Text = player.Tossups.ToString(); item.SubItems[2].Text = player.Duration.ToString(); } } } }
public MatchTeam(Team t, decimal s, MatchPlayer[] players) { this.Players = players; this.Team = t; this.Score = s; }