static void AddSoloMatch() { IPlayerManipulations playerLogic = new PlayerLogic(); IGameManipulations gameLogic = new GameLogic(); IMatchManipulations matchLogic = new MatchLogic(); IRankingSource rankingLogic = new RankingLogic(); // add match between 2 players List<PlayerType> players = playerLogic.GetPlayers(); List<GameType> games = gameLogic.GetGames(); Console.WriteLine("-> adding match (Solo)..."); Console.WriteLine("\t\t#Method AddOrUpdateSoloMatch()"); matchLogic.AddOrUpdateSoloMatch(new SoloMatch(new List<PlayerType> { players[0], players[2] }, new List<int> { 2500, 2300 }, MatchCategories.Competition, games[0])); // print match Console.WriteLine("\t\t#Method GetMatches()"); Console.WriteLine("\t\t#Method SoloMatch.ToString()"); Console.WriteLine("------- First Match -------"); SoloMatch solo = (SoloMatch)matchLogic.GetMatches(games[0], ParticipantTypes.Solo, MatchCategories.Competition)[0]; Console.WriteLine(solo.ToString()); Console.WriteLine("------- @@@@@ -------\n\n"); // print ranking Console.WriteLine("\t\t#Method GetGameRankingsAll()"); Console.WriteLine("------- Ranking Game -------"); foreach (PlayerGameRankingType g in rankingLogic.GetGameRankingsAll(games[0], ParticipantTypes.All)) { Console.WriteLine(g.ToString()); } Console.WriteLine("------- @@@@@ -------\n\n"); // wait for user Wait(); }
private void UpdatePlayerList() { clbPlayers.Items.Clear(); clSoloMembers.Items.Clear(); IPlayerManipulations playerLogic = new PlayerLogic(); foreach (PlayerType player in playerLogic.GetPlayers()) { clbPlayers.Items.Add($"Name: {player.Name} Mail: {player.Mail}"); clSoloMembers.Items.Add($"Name: {player.Name} Mail: {player.Mail}"); } }
/// <summary> /// Updates all rankings (NEEDS VALID SCORES!) /// </summary> private void UpdateRankings() { IPlayerManipulations pm = new PlayerLogic(); // update rankings for (int i = 0; i < backend.RankingList.Count; i++) { PlayerGameRankingType r = backend.RankingList[i]; if (pm.GetGameMatchesForPlayer(r.Game, r.Player).Count < 4) { // player is unranked backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Unranked); continue; } else { // get the scores for the game List <int> scoresInGame = new List <int>(); foreach (PlayerGameRankingType g in backend.RankingList) { if (g.Game == r.Game) { scoresInGame.Add(g.Points); } } // calculate percentile int percentile = CalculatePercentile(scoresInGame, r.Points); // update ranking if (percentile < 10) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Novice); } else if (percentile >= 10 && percentile < 50) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Competent); } else if (percentile >= 50 && percentile < 85) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Advanced); } else { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Elite); } } } backend.SubmitRankingListChanges(); }
static void AddPlayers() { IPlayerManipulations playerLogic = new PlayerLogic(); // add players Console.WriteLine("-> adding players..."); Console.WriteLine("\t\t#Method AddOrUpdatePlayer()"); playerLogic.AddOrUpdatePlayer(new PlayerType("*****@*****.**", "Jonas", "Jonas_tag")); playerLogic.AddOrUpdatePlayer(new PlayerType("*****@*****.**", "Lien", "Lien_tag")); playerLogic.AddOrUpdatePlayer(new PlayerType("*****@*****.**", "Bart", "Bart_tag")); playerLogic.AddOrUpdatePlayer(new PlayerType("*****@*****.**", "Yana", "Yana_tag")); // print players Console.WriteLine("\t\t#Method PlayerType.ToString()"); Console.WriteLine("------- Players -------"); foreach (PlayerType p in playerLogic.GetPlayers()) { Console.WriteLine(" " + p.ToString()); } Console.WriteLine("------- @@@@@ -------\n\n"); // wait for user Wait(); }
/// <summary> /// Updates all rankings (NEEDS VALID SCORES!) /// </summary> private void UpdateRankings() { IPlayerManipulations pm = new PlayerLogic(); // update rankings for (int i = 0; i < backend.RankingList.Count; i++) { PlayerGameRankingType r = backend.RankingList[i]; if (pm.GetGameMatchesForPlayer(r.Game, r.Player).Count < 4) { // player is unranked backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Unranked); continue; } else { // get the scores for the game List<int> scoresInGame = new List<int>(); foreach (PlayerGameRankingType g in backend.RankingList) { if (g.Game == r.Game) { scoresInGame.Add(g.Points); } } // calculate percentile int percentile = CalculatePercentile(scoresInGame, r.Points); // update ranking if (percentile < 10) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Novice); } else if (percentile >= 10 && percentile < 50) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Competent); } else if (percentile >= 50 && percentile < 85) { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Advanced); } else { backend.RankingList[i] = new PlayerGameRankingType(backend.RankingList[i].Game, backend.RankingList[i].Player, backend.RankingList[i].Points, Ranks.Elite); } } } backend.SubmitRankingListChanges(); }
static void AddTeamMatch() { IPlayerManipulations playerLogic = new PlayerLogic(); IGameManipulations gameLogic = new GameLogic(); ITeamManipulations teamLogic = new TeamLogic(); IMatchManipulations matchLogic = new MatchLogic(); IRankingSource rankingLogic = new RankingLogic(); List<PlayerType> players = playerLogic.GetPlayers(); List<GameType> games = gameLogic.GetGames(); // add team Console.WriteLine("-> adding teams..."); Console.WriteLine("\t\t#Method AddOrUpdateTeam()"); teamLogic.AddOrUpdateTeam(new TeamType("FirstTeam", new List<PlayerType> { players[0] })); teamLogic.AddOrUpdateTeam(new TeamType("SecondTeam", new List<PlayerType> { players[2] })); // print teams Console.WriteLine("\t\t#Method TeamType.ToString()"); Console.WriteLine("------- Teams Game -------"); foreach (TeamType t in teamLogic.GetTeams()) { Console.WriteLine(t.ToString()); } Console.WriteLine("------- @@@@@ -------\n\n"); // wait for user Wait(); // add match between 2 teams Console.WriteLine("-> adding team match..."); Console.WriteLine("\t\t#Method GetTeams()"); List<TeamType> teams = teamLogic.GetTeams(); Console.WriteLine("\t\t#Method AddOrUpdateTeamMatch()"); matchLogic.AddOrUpdateTeamMatch(new TeamMatch(MatchCategories.Competition, games[0], new List<TeamType> { teams[0], teams[1] }, new List<int> { 200, 3000 })); // print match Console.WriteLine("\t\t#Method GetMatchesForTeam()"); Console.WriteLine("------- First Team Match -------"); TeamMatch team = (TeamMatch)teamLogic.GetMatchesForTeam(teams[0])[0]; Console.WriteLine(team.ToString()); Console.WriteLine("------- @@@@@ -------\n\n"); // print ranking Console.WriteLine("\t\t#Method GetGameRankingsAll()"); Console.WriteLine("------- Ranking Game -------"); foreach (PlayerGameRankingType g in rankingLogic.GetGameRankingsAll(games[0], ParticipantTypes.All)) { Console.WriteLine(g.ToString()); } Console.WriteLine("------- @@@@@ -------\n\n"); // wait for user Wait(); }
private void UpdateTree() { IRankingSource rankingLogic = new RankingLogic(); IGameManipulations gameLogic = new GameLogic(); ITeamManipulations teamLogic = new TeamLogic(); IPlayerManipulations playerLogic = new PlayerLogic(); IMatchManipulations matchLogic = new MatchLogic(); List<GameType> games = gameLogic.GetGames(); List<TeamType> teams = teamLogic.GetTeams(); List<PlayerType> players = playerLogic.GetPlayers(); // ranking tree treeRankings.BeginUpdate(); treeRankings.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { List<PlayerGameRankingType> r = rankingLogic.GetGameRankingsAll(games[i], ParticipantTypes.All); treeRankings.Nodes.Add(games[i].Name); for (int j = 0; j < r.Count; j++) { treeRankings.Nodes[i].Nodes.Add("Player: " + r[j].Player.Name); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Mail: " + r[j].Player.Mail); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Tag: " + r[j].Player.Tag); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Points: " + r[j].Points); treeRankings.Nodes[i].Nodes[j].Nodes.Add("Ranking: " + r[j].Ranking); } } treeRankings.EndUpdate(); // games tree treeGames.BeginUpdate(); treeGames.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { treeGames.Nodes.Add(games[i].Name); treeGames.Nodes[i].Nodes.Add("Participant type: " + games[i].ParticipantType.ToString()); } treeGames.EndUpdate(); // teams tree treeTeams.BeginUpdate(); treeTeams.Nodes.Clear(); for (int i = 0; i < teams.Count; i++) { treeTeams.Nodes.Add(teams[i].Name); for (int j = 0; j < teams[i].Members.Count; j++) { treeTeams.Nodes[i].Nodes.Add($"Player: {teams[i].Members[j].Name} - {teams[i].Members[j].Tag} - {teams[i].Members[j].Mail}"); } } treeTeams.EndUpdate(); // players tree treePlayers.BeginUpdate(); treePlayers.Nodes.Clear(); for (int i = 0; i < players.Count; i++) { treePlayers.Nodes.Add(players[i].Name); treePlayers.Nodes[i].Nodes.Add("Tag: " + players[i].Tag); treePlayers.Nodes[i].Nodes.Add("Mail: " + players[i].Mail); } treePlayers.EndUpdate(); // matches tree treeMatches.BeginUpdate(); treeMatches.Nodes.Clear(); for (int i = 0; i < games.Count; i++) { List<MatchType> matches = matchLogic.GetMatchesAll(games[i]); treeMatches.Nodes.Add($"Matches for: {games[i].Name}"); for (int j = 0; j < matches.Count; j++) { if (matches[j] is SoloMatch) { SoloMatch s = (SoloMatch)matches[j]; treeMatches.Nodes[i].Nodes.Add(s.dateTime.ToString()); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Name: {s.GameID.Name}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Type: {s.GameID.ParticipantType.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Category: {s.Category.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add("Players & scores"); for (int k = 0; k < s.Players.Count; k++) { treeMatches.Nodes[i].Nodes[j].Nodes[3].Nodes.Add($"Player: {s.Players[k].Name} : {s.Scores[k]}"); } } else if (matches[j] is TeamMatch) { TeamMatch t = (TeamMatch)matches[j]; treeMatches.Nodes[i].Nodes.Add(t.dateTime.ToString()); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Name: {t.GameID.Name}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Type: {t.GameID.ParticipantType.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add($"Category: {t.Category.ToString()}"); treeMatches.Nodes[i].Nodes[j].Nodes.Add("Teams & scores"); for (int k = 0; k < t.Teams.Count; k++) { treeMatches.Nodes[i].Nodes[j].Nodes[3].Nodes.Add($"Team: {t.Teams[k].Name} : {t.Scores[k]}"); } } } } treeMatches.EndUpdate(); }
private void btnAddSoloMatch_Click(object sender, EventArgs e) { IMatchManipulations matchLogic = new MatchLogic(); IPlayerManipulations playerLogic = new PlayerLogic(); IGameManipulations gameLogic = new GameLogic(); try { List<PlayerType> players = new List<PlayerType>(); MatchCategories cat = (MatchCategories)Enum.Parse(typeof(MatchCategories), downUpSoloCat.SelectedItem.ToString()); GameType game = gameLogic.GetGames()[downUpSoloGame.SelectedIndex]; List<int> scores = new List<int>(); string[] parts = tbSoloScores.Text.Split(','); foreach (string s in parts) { scores.Add(int.Parse(s)); } for (int i = 0; i < clSoloMembers.CheckedItems.Count; i++) { players.Add(playerLogic.GetPlayers()[clSoloMembers.Items.IndexOf(clSoloMembers.CheckedItems[i])]); } if ((players.Count > 0) && (players.Count == scores.Count)) { matchLogic.AddOrUpdateSoloMatch(new SoloMatch(players, scores, cat, game)); tbSoloScores.Text = ""; } else { MessageBox.Show("Invalid scores.", "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error: Add Match", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateTree(); }
private void btnAddTeam_Click(object sender, EventArgs e) { IPlayerManipulations playerLogic = new PlayerLogic(); ITeamManipulations teamLogic = new TeamLogic(); List<PlayerType> players = new List<PlayerType>(); if (tbTeamName.Text != "") { try { for (int i = 0; i < clbPlayers.CheckedItems.Count; i++) { players.Add(playerLogic.GetPlayers()[clbPlayers.Items.IndexOf(clbPlayers.CheckedItems[i])]); } if (players.Count > 0) { teamLogic.AddOrUpdateTeam(new TeamType(tbTeamName.Text, players)); tbTeamName.Text = ""; UpdateTeamList(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error: Add Team", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Team needs a name.", "Error: Add Team", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateTree(); }
private void btnAddPlayer_Click(object sender, EventArgs e) { IPlayerManipulations playerLogic = new PlayerLogic(); if (tbAddPlayerName.Text != "") { try { playerLogic.AddOrUpdatePlayer(new PlayerType(tbAddPlayerMail.Text, tbAddPlayerName.Text, tbAddPlayerTag.Text)); tbAddPlayerMail.Text = ""; tbAddPlayerName.Text = ""; tbAddPlayerTag.Text = ""; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error: Add Player", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Player needs a name.", "Error: Add Player", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdatePlayerList(); UpdateTree(); }