public static void Print(Competion competion) { if (competion == null) { throw new ArgumentNullException(nameof(competion)); } var printPlayers = new ConsoleTable("Player"); var printWinners = new ConsoleTable("Comp ID", "Game ID", "Winner"); var printCompetitors = new ConsoleTable("Game ID", "Name", "Score", "Winner"); foreach (var name in competion.Players.Select(p => p.FullName)) { printPlayers.AddRow(name); } foreach (var game in competion.Games) { printWinners.AddRow(competion.Id, game.Id, game.Winner.Player.FullName); foreach (var competitor in game.Competitors) { printCompetitors.AddRow(game.Id, competitor.Player.FullName, competitor.Score, competitor.Id == game.Winner.Id ? ":) - Winner" : ":("); } } printPlayers.Write(Format.Minimal); printWinners.Write(Format.Minimal); printCompetitors.Write(Format.Minimal); }
private static void PrintCompetition(Competion competion) { Kv("Competition ID", competion.Id); PrintPlayers(competion); PrintGames(competion); }
public static void Print(Competion competion) { if (competion == null) { throw new ArgumentNullException(nameof(competion)); } var printPlayers = new Table("Player"); var printWinners = new Table("Comp ID", "Game ID", "Winner"); var printCompetitors = new Table("Game ID", "Name", "Score", "Winner"); // printWinners.Config = TableConfiguration.Markdown(); printPlayers.Config = TableConfiguration.Unicode(); printWinners.Config = TableConfiguration.Unicode(); printCompetitors.Config = TableConfiguration.Unicode(); foreach (var name in competion.Players.Select(p => p.FullName)) { printPlayers.AddRow(name); } foreach (var game in competion.Games) { printWinners.AddRow(competion.Id, game.Id, game.Winner.Player.FullName); foreach (var competitor in game.Competitors) { printCompetitors.AddRow(game.Id, competitor.Player.FullName, competitor.Score, competitor.Id == game.Winner.Id ? ":) - Winner" : ":("); } } var tables = new ConsoleTables(printPlayers, printWinners, printCompetitors); Console.Write(tables.ToString()); }
private static void PrintPlayers(Competion competion) { Kv("# of players", competion.Players.Count); var playerNames = competion.Players.Select(p => p.FullName); Kv("Player names", string.Join(", ", playerNames)); }
// ToDo: Read Dependency Injection private static void Execute(DomainContext context, string[] playerNames) { Console.WriteLine("Create Context"); var competion = new Competion(); context.Competions.Add(competion); // context.Players.AddIfNotExist((p) => p.Name == "david" ) competion.RegisterPlayers(playerNames); competion.GenerateGames(); competion.Start(); context.SaveChanges(); PrintCompetition(competion); }
private static void RegisterPlayers(Competion competion) { Console.WriteLine("Register Players"); competion.AddPlayer("David"); competion.AddPlayer("Lisa"); competion.AddPlayer("James"); competion.AddPlayer("Reynaldo"); competion.AddPlayer("Frederick"); competion.AddPlayer("Jenny"); competion.AddPlayer("Paul"); competion.AddPlayer("Laura"); competion.AddPlayer("Steve"); competion.AddPlayer("Rueben"); competion.AddPlayer("Robert"); competion.AddPlayer("Sandra"); competion.AddPlayer("Allison"); }
private static void PrintGames(Competion competion) { foreach (var game in competion.Games) { Kv("Game ID", game.Id); Kv("# of competitors in game", game.Competitors.Count); // var playerNames = game.Competitors.Select(c => c.Player.FullName); // Kv("Competitor names in game", string.Join(", ", playerNames)); // var playerResults = game.Competitors.Select(c => string.Format("{0}: ({1})", c.Player.FullName, c.Score)); var playerResults = game.Competitors.Select(c => $"{c.Player.FullName}: ({c.Score})"); Kv("Competitor results", string.Join(", ", playerResults)); Kv("Winner", game.Winner.Player.FullName); Line(); } }
public static void Print(Competion competion) { if (competion == null) { throw new ArgumentNullException(nameof(competion)); } // var printPlayers = new ConsoleTable("Player"); // var printWinners = new ConsoleTable("Comp ID", "Game ID", "Winner"); // var printCompetitors = new ConsoleTable("Game ID", "Name", "Score", "Winner"); var players = competion .Players .Select(p => new { PlayerName = p.FullName }) .ToList(); // ConsoleTableBuilder.From(players).WithFormat(ConsoleTableBuilderFormat.MarkDown).ExportAndWriteLine(); ConsoleTableBuilder .From(players) .WithTitle("PLAYERS", ConsoleColor.Red) .WithFormat(ConsoleTableBuilderFormat.MarkDown) .ExportAndWriteLine(); var games = competion .Games .Select(g => new { CompetitionId = competion.Id, GameId = g.Id, Winner = g.Winner.Player.FullName }) .ToList(); ConsoleTableBuilder .From(games) .WithTitle("Games", ConsoleColor.Red) .WithFormat(ConsoleTableBuilderFormat.MarkDown) .ExportAndWriteLine(); var gameCompetitors = competion .Games .Select(game => new { GameId = game.Id, Winner = game.Winner.Player.FullName, Competitors = string.Join( " | ", game.Competitors.Select(competitor => $"{competitor.Player.FullName,-10} {(competitor.Id == game.Winner.Id ? "WIN" : string.Empty),-3} ({competitor.Score,-1})")) }).ToList(); // var gameCompetitors = competion // .Games // .Select(game => new { // GameId = game.Id, // Winner = game.Winner.Player.FullName, // Competitors = game.Competitors.Select(competitor => new { // Score = competitor.Score, // Message = competitor.Id == game.Winner.Id ? "Winner" : string.Empty // }) // }).ToList(); ConsoleTableBuilder .From(gameCompetitors) .WithTitle("Game Competitors", ConsoleColor.Red) .WithFormat(ConsoleTableBuilderFormat.MarkDown) .ExportAndWriteLine(); }