private void Loading_Click(object sender, RoutedEventArgs e) { _tournament = BinarySaver.LoadSingleFromBinnary(); if (_tournament != null) { BracketDrawing.DrawSingleElimination(_tournament, UpperBracketCanvas); Tournament.KeyUp += SingleEliminationTournament_KeyUp; HideElements(); return; } _tournament = BinarySaver.LoadDoubleFromBinnary(); if (_tournament != null) { var doubleElimination = _tournament as DoubleEliminationTournament; BracketDrawing.DrawDoubleElimination(doubleElimination, UpperBracketCanvas, LowerBracketCanvas); Tournament.KeyUp += DoubleEliminationTournament_KeyUp; HideElements(); return; } MessageBox.Show("There is no saved tournament"); return; }
private void Start_Click(object sender, RoutedEventArgs e) { var participantsList = new List <string>(); foreach (var item in PartisipantsList.Items) { participantsList.Add(item.ToString()); } if (SingleElimination.IsChecked == true) { _tournament = new SingleEliminationTournament(participantsList); Tournament.KeyUp += SingleEliminationTournament_KeyUp; } else { _tournament = new DoubleEliminationTournament(participantsList); Tournament.KeyUp += DoubleEliminationTournament_KeyUp; } HideElements(); List <Participant> bracket = _tournament.GetBracket(); BracketDrawing.DrawSingleElimination(_tournament, UpperBracketCanvas); }
private void SingleEliminationTournament_KeyUp(object sender, KeyEventArgs e) { if (e.Key != Key.Space) { return; } if (_tournament.EndOfTheGame()) { return; } var meeting = _tournament.GetPlayingParticipants(); var side = ReturnWinner(meeting); _tournament.PlayGame(side); BracketDrawing.DrawSingleElimination(_tournament, UpperBracketCanvas); }
private void DrawBracket(Canvas canvas, List <Participant> bracket) { canvas.Children.Clear(); int maxDepth = 0; foreach (var participant in bracket) { if (MaxDepth(participant) > maxDepth) { maxDepth = MaxDepth(participant); } } int i = 0; foreach (var participant in bracket) { var newParticipant = CloneParticipant.Clone(participant); BracketDrawing.AddLinkToCanvas(ref i, maxDepth, newParticipant, canvas); } }