/// <summary> /// Constructs a new match /// </summary> /// <param name="id">the unique id for this match</param> /// <param name="dt">the date on which this match was played</param> /// <param name="team1">the match information for the first team</param> /// <param name="team2">the match information for the second team</param> public Match(int id, DateTime dt, MatchTeam team1, MatchTeam team2) { this.Date = dt; this.FirstTeam = team1; this.SecondTeam = team2; this.ID = id; }
/// <summary> /// Clones this Match /// </summary> /// <returns></returns> public Match Clone() { MatchTeam firstTeam = new MatchTeam(this.FirstTeam.Team, this.FirstTeam.Score, this.FirstTeam.Players); MatchTeam secondTeam = new MatchTeam(this.SecondTeam.Team, this.SecondTeam.Score, this.SecondTeam.Players); return(new Match(this.ID, this.Date, firstTeam, secondTeam)); }
public void AddMatch(DateTime dt, MatchTeam team1, MatchTeam team2) { int id; while (this.MatchExists(id = rand.Next())) { ; } matches.Add(new Match(id, dt, team1, team2)); }
private void ViewPlayer_Load(object sender, EventArgs e) { playerBox.Text = player.Name; schoolBox.Text = player.Team.School.Name; teamBox.Items.AddRange(player.Team.School.Teams.Keys.ToArray()); teamBox.SelectedItem = player.Team.Name; tossupBox.Text = MainForm.AllMatches.GetTotalTossups(player).ToString(); gamesBox.Text = MainForm.AllMatches.GetGamesPlayed(player).ToString(); decimal avg = MainForm.AllMatches.GetAverage(player); if (avg > -1) { avgBox.Text = avg.ToString("0.###"); } else { avgBox.Text = "--"; } decimal wins = 0, losses = 0; foreach (Match match in MainForm.AllMatches.GetMatches(player)) { MatchPlayer mPlayer = match.GetPlayer(player); MatchTeam opponent = match.GetOppenent(player); string result; if (match.Winner.Players.ToList().Contains(mPlayer)) { result = "W"; wins++; } else { result = "L"; losses++; } ListViewItem item = new ListViewItem(); item.Text = match.Date.ToShortDateString(); item.SubItems.Add(opponent.Team.School.Name + " - " + opponent.Name); item.SubItems.Add(mPlayer.Tossups.ToString()); item.SubItems.Add(mPlayer.Duration.ToString()); item.SubItems.Add(result); matches.Add(item, match); matchListView.Items.Add(item); } winsBox.Text = wins.ToString(); lossesBox.Text = losses.ToString(); if ((wins + losses) > 0) { winpctBox.Text = (wins * 100 / (wins + losses)).ToString("0.##") + "%"; } else { winpctBox.Text = "--"; } }
/// <summary> /// Adds a match to a list (assigning it a unique id) /// </summary> /// <param name="dt"></param> /// <param name="team1"></param> /// <param name="team2"></param> /// <param name="matches"></param> /// <returns></returns> static List <Match> AddMatch(DateTime dt, MatchTeam team1, MatchTeam team2, List <Match> matches) { int id; while (MatchExists(id = rand.Next(), matches)) { ; } matches.Add(new Match(id, dt, team1, team2)); return(matches); }
/// <summary> /// Clones this Match /// </summary> /// <returns></returns> public Match Clone() { MatchTeam firstTeam = new MatchTeam(this.FirstTeam.Team, this.FirstTeam.Score, this.FirstTeam.Players); MatchTeam secondTeam = new MatchTeam(this.SecondTeam.Team, this.SecondTeam.Score, this.SecondTeam.Players); return new Match(this.ID, this.Date, firstTeam, secondTeam); }
private void button5_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { toolTip1.ToolTipTitle = "No Score Has Been Entered!"; toolTip1.Show("You have not entered a final score for this team.", textBox1); textBox1.Focus(); return; } if (textBox2.Text.Equals("")) { toolTip1.ToolTipTitle = "No Score Has Been Entered!"; toolTip1.Show("You have not entered a final score for this team.", textBox2); textBox2.Focus(); return; } decimal score1 = decimal.Parse(textBox1.Text); decimal score2 = decimal.Parse(textBox2.Text); if (score1 == score2) { MessageBox.Show(this, "This match indicates a tie!\r\nOne team must have a higher score than the other.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); return; } List<MatchPlayer> team1Players = new List<MatchPlayer>(); foreach (PlayerControl p in playerList1.Items) { if (!p.IsEmpty) { if (!p.CheckInfo(toolTip1)) { return; } team1Players.Add(new MatchPlayer(p.Player, p.Tossups, p.Durration)); } } MatchTeam team1 = new MatchTeam(Schools[comboBox1.SelectedItem.ToString()] .Teams[comboBox2.SelectedItem.ToString()], score1, team1Players.ToArray()); List<MatchPlayer> team2Players = new List<MatchPlayer>(); foreach (PlayerControl p in playerList2.Items) { if (!p.IsEmpty) { if (!p.CheckInfo(toolTip1)) { return; } team2Players.Add(new MatchPlayer(p.Player, p.Tossups, p.Durration)); } } MatchTeam team2 = new MatchTeam(Schools[comboBox4.SelectedItem.ToString()] .Teams[comboBox3.SelectedItem.ToString()], score2, team2Players.ToArray()); AllMatches.AddMatch(dateTimePicker1.Value, team1, team2); label12.Show(); timer1.Start(); reload(); }
private void button5_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { toolTip1.ToolTipTitle = "No Score Has Been Entered!"; toolTip1.Show("You have not entered a final score for this team.", textBox1); textBox1.Focus(); return; } if (textBox2.Text.Equals("")) { toolTip1.ToolTipTitle = "No Score Has Been Entered!"; toolTip1.Show("You have not entered a final score for this team.", textBox2); textBox2.Focus(); return; } decimal score1 = decimal.Parse(textBox1.Text); decimal score2 = decimal.Parse(textBox2.Text); if (score1 == score2) { MessageBox.Show(this, "This match indicates a tie!\r\nOne team must have a higher score than the other.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textBox1.Focus(); return; } List <MatchPlayer> team1Players = new List <MatchPlayer>(); foreach (PlayerControl p in playerList1.Items) { if (!p.IsEmpty) { if (!p.CheckInfo(toolTip1)) { return; } team1Players.Add(new MatchPlayer(p.Player, p.Tossups, p.Durration)); } } MatchTeam team1 = new MatchTeam(Schools[comboBox1.SelectedItem.ToString()] .Teams[comboBox2.SelectedItem.ToString()], score1, team1Players.ToArray()); List <MatchPlayer> team2Players = new List <MatchPlayer>(); foreach (PlayerControl p in playerList2.Items) { if (!p.IsEmpty) { if (!p.CheckInfo(toolTip1)) { return; } team2Players.Add(new MatchPlayer(p.Player, p.Tossups, p.Durration)); } } MatchTeam team2 = new MatchTeam(Schools[comboBox4.SelectedItem.ToString()] .Teams[comboBox3.SelectedItem.ToString()], score2, team2Players.ToArray()); AllMatches.AddMatch(dateTimePicker1.Value, team1, team2); label12.Show(); timer1.Start(); reload(); }