private void Start() { if (PlayAreas.Count == 0) { MessengerInstance.Send(new NoPlayAreaDefinedMessage()); return; } if (TeamCount != Teams.Count()) { MessengerInstance.Send(new TeamCountMismatchMessage(Model.Id.Value, Teams.Count, TeamCount)); return; } if (HasChanges) { bool abortStart = true; MessengerInstance.Send(new AreYouSureMessage("Ungespeicherte Änderungen", "Es gibt noch ungespeicherte Änderungen.\nDiese müssen gespeichert werden vor dem Start.\nWollen Sie jetzt speichern und fortfahren?", () => { abortStart = false; })); if (abortStart) { return; } SaveChangesCommand.Execute(null); } try { var resp = App.RestClient.StartWithHttpMessagesAsync(Id); resp.ContinueWith(t => { Model = resp.Result.Body; UpdateFromModel(Model); } ); } catch (Exception e) { if (e.GetType() == typeof(AggregateException) || e.GetType() == typeof(Microsoft.Rest.HttpOperationException)) { MessengerInstance.Send(new CommunicationErrorMessage()); } else { throw e; } } // Alle Properties => RaisePropertyChanged / Command.CanExecute updaten }
public void GenerateSchedule() { if (Teams.Count < 2 || Teams.Count % 2 != 0) { return; } Matches = new List <Match>(); var n = Teams.Count(); //k reprezinta etapa for (int k = 0; k < n - 1; k++) { // i reprezinta nr meciului din etapa k for (int i = 0; i < n / 2; i++) { if (k % 2 == 0) { Matches.Add(new Match { Home = Teams[i], Guest = Teams[n - 1 - i], Round = k + 1 }); } else { Matches.Add(new Match { Home = Teams[n - 1 - i], Guest = Teams[i], Round = k + 1 }); } } var last = Teams.Last(); Teams.Remove(last); Teams.Insert(1, last); } var returnMatches = new List <Match>(); foreach (var match in Matches) { returnMatches.Add(new Match { Home = match.Guest, Guest = match.Home, Round = n - 1 + match.Round }); } Matches.AddRange(returnMatches); }
public override void Update(GameTime gameTime) { int pCountAlive = Teams.Count((t) => IsAlive(t)); if (pCountAlive > 1) { return; //still running } if (pCountAlive == 1) { GameEnded = true; WinningTeam = Teams.First((t) => IsAlive(t)); return; } if (pCountAlive == 0) { GameEnded = true; WinningTeam = Team.Indeterminate; return; } }
public DomainResult StartSeason() { if (Teams.Count() < 2) { return(DomainResult.Error(new SeasonMustHaveAtLeast2Teams(Teams.Count()))); } if (TeamCountIsUneven()) { return(DomainResult.Error(new CanNotStartSeasonWithUnevenTeamCount(Teams.Count()))); } if (SeasonIsStarted) { return(DomainResult.Error(new CanNotStartSeasonASecondTime())); } var matchPairingService = new MatchPairingService(); var gameDays = matchPairingService.ComputePairings(Teams).ToList(); var seasonStarted = new SeasonStarted(SeasonId, gameDays, DateTimeOffset.UtcNow); return(DomainResult.Ok(seasonStarted)); }
private bool TeamCountIsUneven() { return(Teams.Count() % 2 != 0); }
public virtual int CountAliveTeams() { return(Teams.Count(t => t.Dead.Count < t.Count)); }
private static Table CreateTable(int UserChoice, ref List <Game> Games) { Table output = null; List <string[]> AssembledRows = new List <string[]>(); if (UserChoice == 0) { foreach (Game game in Games) { string[] row = new string[] { game.WinningTeam.Name, game.WinningTeam.Year.ToString(), game.WinningTeam.QBToString(), game.WinningTeam.Coach, game.MVP, (game.WinningTeam.Points - game.LosingTeam.Points).ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("List of all super bowl winners", new string[] { "Winning Team", "Year", "Winning Quaterback(s)", "Winning Coach", "MVP", "Point difference" }, AssembledRows); } else if (UserChoice == 1) { var AttendenceQuery = from game in Games orderby game.Attendance descending select game; Game[] QueryArray = AttendenceQuery.ToArray(); for (int i = 0; i < 5; i++) { Game focusedGame = QueryArray[i]; string[] row = new string[] { focusedGame.Attendance.ToString(), focusedGame.Year.ToString(), focusedGame.WinningTeam.Name, focusedGame.LosingTeam.Name, focusedGame.City, focusedGame.State, focusedGame.Stadium }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Top five attended super bowls", new string[] { "Attendance", "Year", "Winning Team", "Losing Team", "City", "State", "Stadium" }, AssembledRows); } else if (UserChoice == 2) { var MostHostedQuery = from game in Games group game by game.State into StateGroups orderby StateGroups.Count() descending select StateGroups; var State = MostHostedQuery.First(); foreach (Game game in State) { string[] row = new string[] { game.City, game.State, game.Stadium }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("The state that hosted the most super bowls", new string[] { "Cities", "State", "Stadiums" }, AssembledRows); } else if (UserChoice == 3) { //Generate a list of players who won MVP more than once and output the following: /*Name of MVP * The winning team * The losing team*/ var MVPQuery = from game in Games group game by game.MVP into Players where Players.Count() > 1 orderby Players.Count() descending select Players; foreach (var player in MVPQuery) { foreach (var game in player) { string[] row = new string[] { game.MVP, game.WinningTeam.Name, game.LosingTeam.Name }; AssembledRows.Add(row); } } AssembledRows.TrimExcess(); output = new Table("Players who have won MVP more than once", new string[] { "Name of MVP", "Winning Team", "Losing Team" }, AssembledRows); } else if (UserChoice == 4) { //Which coach lost the most super bowls? var CoachLostQuery = from game in Games group game by game.LosingTeam.Coach into Coaches let Lose = Coaches.Count() orderby Coaches.Count() descending select new { Coaches.Key, Lose }; var MostLostCoach = from coach in CoachLostQuery let Most = CoachLostQuery.First().Lose where coach.Lose == Most select coach; foreach (var coach in MostLostCoach) { string[] row = new string[] { coach.Key, coach.Lose.ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Coach(es) that lost the most super bowls", new string[] { "Name of Coach", "Number of Losts" }, AssembledRows); } else if (UserChoice == 5) { //Which coach won the most super bowls? var CoachWinQuery = from game in Games group game by game.WinningTeam.Coach into Coaches let Wins = Coaches.Count() orderby Coaches.Count() descending select new { Coaches.Key, Wins }; var MostWinCoach = from coach in CoachWinQuery let Most = CoachWinQuery.First().Wins where coach.Wins == Most select coach; foreach (var coach in MostWinCoach) { string[] row = new string[] { coach.Key, coach.Wins.ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Coach(es) that won the most super bowls", new string[] { "Name of Coach", "Number of Wins" }, AssembledRows); } else if (UserChoice == 6) { //Which team(s) won the most super bowls? var TeamWinQuery = from game in Games group game by game.WinningTeam.Name into Teams let Wins = Teams.Count() orderby Teams.Count() descending select new { Teams.Key, Wins }; var MostWinTeams = from team in TeamWinQuery let Most = TeamWinQuery.First().Wins where team.Wins == Most select team; foreach (var team in MostWinTeams) { string[] row = new string[] { team.Key, team.Wins.ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Team that won the most super bowls", new string[] { "Name of Team", "Number of wins" }, AssembledRows); } else if (UserChoice == 7) { //Which team(s) lost the most super bowls? var TeamLoseQuery = from game in Games group game by game.WinningTeam.Name into Teams let Lose = Teams.Count() orderby Teams.Count() descending select new { Teams.Key, Lose }; var MostLoseTeams = from team in TeamLoseQuery let Most = TeamLoseQuery.First().Lose where team.Lose == Most select team; foreach (var team in MostLoseTeams) { string[] row = new string[] { team.Key, team.Lose.ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Team that won the most super bowls", new string[] { "Name of Team", "Number of losts" }, AssembledRows); } else if (UserChoice == 8) { //Which Super bowl had the greatest point difference? var ScoreQuery = from game in Games let diff = game.WinningTeam.Points - game.LosingTeam.Points orderby diff descending select new { game.RomanOccurance, WinName = game.WinningTeam.Name, LoseName = game.LosingTeam.Name, game.Date, diff }; var MostDiffTeams = from team in ScoreQuery let Most = ScoreQuery.First().diff where team.diff == Most select team; foreach (var game in MostDiffTeams) { string[] row = new string[] { game.RomanOccurance, game.Date, game.WinName, game.LoseName, game.diff.ToString() }; AssembledRows.Add(row); } AssembledRows.TrimExcess(); output = new Table("Super bowl(s) with the greatest point difference", new string[] { "nth Super Bowl", "Date", "Winning Team", "Losing Team", "Point difference" }, AssembledRows); } else if (UserChoice == 9) { //What is the average attendance of all super bowls? var AttendanceQuery = from game in Games let TotalAttendance = +game.Attendance select TotalAttendance; double averageAttendance = AttendanceQuery.Average(); AssembledRows.Add(new string[] { averageAttendance.ToString() }); AssembledRows.TrimExcess(); output = new Table("", new string[] { "Average Attendance" }, AssembledRows); } else if (UserChoice == 10) { Exit(); } return(output); }
private void MainMenu() { try { int choice = terminal.MainMenu(Matches, Teams, new string[] { "Tabelle anzeigen", "Spielergebnis hinzufügen", "Team hinzufügen", "Team entfernen", "Mitglied hinzufügen", "Mitglied Teamwechsel", "Mitglied entfernen", "Programm beenden" }); if (choice != 7) { if (choice == 0) { //Tabelle aktualisieren if (Repository.IsDirty()) //TODO: insert dirty joke here! { switch (Terminal.Menu(new string[] { "Speichern", "Verwerfen" }, "Sie haben ungespeicherte Änderungen\nMöchten Sie diese Speichern oder Verwerfen?")) { case 0: Repository.Flush(); break; default: break; } } MainMenu(); } else if (choice == 1) { //Spielergebnis hinzufügen int?day = null; //spieltag foreach (Team team in Teams) { int teamMatchesAmount = Matches.Where(x => x.Team == team || x.Opponent == team).Count(); if (day == null || day > teamMatchesAmount) { day = teamMatchesAmount; } else { } } int gameday; if ((int?)day == null) { gameday = 1; } else { gameday = (int)day; } List <Team> possibleTeams = Teams.Where(x => (Matches.Where(y => y.Team == x || y.Opponent == x).Count() <= gameday)).ToList(); if (possibleTeams.Count() < 2) { throw new Exception.NoElementsException(); } else { } Team HomeTeam = possibleTeams[Terminal.Menu(possibleTeams.Select(x => x.Name).ToArray(), "Bitte Team wählen")]; List <Team> possibleGuests = possibleTeams.Where(x => x != HomeTeam).ToList(); Team GuestTeam = possibleGuests[Terminal.Menu(possibleGuests.Select(x => x.Name).ToArray(), "Bitte Team wählen")]; Match match = new Match( null, HomeTeam, GuestTeam, Terminal.AskForInteger("Tore eingeben"), Terminal.AskForInteger("Gegentore Tore eingeben") ); Repository.Save(match); MainMenu(); } else if (choice == 2) { //Team hinzufügen if (Teams.Count() < League.MaximumTeams) { Repository.Save(new Team(null, Terminal.AskForString("Team Name"), League)); } else { Terminal.Message("Maximal " + League.MaximumTeams + " Teams"); } MainMenu(); } else if (choice == 3) { //Team entfernen if (Teams.Count() < 1) { throw new Exception.NoElementsException(); } else { } Team team = Teams[Terminal.Menu(Teams.Select(i => i.Name).ToArray(), "Team löschen")]; team.League = null; Repository.Save(team); MainMenu(); } else if (choice == 4) { //Spieler entfernen if (Teams.Count() < 1) { throw new Exception.NoElementsException(); } else { } //Spieler hinzufügen Repository.Save( new Member( null, Terminal.AskForString("Name"), Teams[Terminal.Menu(Teams.Select(x => x.Name).ToArray(), "Bitte Team wählen")], Roles[Terminal.Menu(Roles.Select(x => x.Name).ToArray(), "Bitte Rolle wählen")]) ); MainMenu(); } else if (choice == 5) { //Spieler entfernen if (Teams.Count() < 2 || Members.Count() < 1) { throw new Exception.NoElementsException(); } else { } //Spieler Teamwechsel Team team = Teams[Terminal.Menu(Teams.Select(x => x.Name).ToArray(), "Bitte wählen")]; List <Member> teamMembers = Members.Where(x => x.Team == team).ToList(); Member member = teamMembers[Terminal.Menu(teamMembers.Select(x => " [" + x.Role.Name + "] " + x.Name).ToArray(), "Bitte wählen")]; member.Team = Teams.Where(x => x != member.Team).ToArray()[Terminal.Menu(Teams.Where(x => x != member.Team).Select(x => x.Name).ToArray(), "Bitte wählen")]; Repository.Save(member); MainMenu(); } else if (choice == 6) { //Spieler entfernen if (Teams.Count() < 1 || Members.Count() < 1) { throw new Exception.NoElementsException(); } else { } Team team = Teams[Terminal.Menu(Teams.Select(x => x.Name).ToArray(), "Bitte wählen")]; List <Member> teamMembers = Members.Where(x => x.Team == team).ToList(); Member member = teamMembers[Terminal.Menu(teamMembers.Select(x => " [" + x.Role.Name + "] " + x.Name).ToArray(), "Bitte wählen")]; member.Team = null; Repository.Save(member); MainMenu(); } else { } } else { Repository.Flush(); if (debug) { //wait a moment to view debug logs System.Threading.Thread.Sleep(1000); } else { } } } catch (Exception.NoElementsException) { Terminal.Message("Fehler\n Die Liste ist leer!"); MainMenu(); } }