Exemple #1
0
        private static void Display(TournamentController tournament)
        {
            Console.Clear();
            Console.WriteLine("Type \"play {type of match} {number of tour} {number of match} {number of winner}\" to enter match results.");
            Console.WriteLine("Type is one of 3 options: \"{0}\", \"{1}\" or \"{2}\". For finale you need only the number of winner.", PlayMain, PlayLosers, PlayFinale);
            Console.WriteLine("Tours and matches are counted from 1. Number of winner is either 1 or 2.");
            Console.WriteLine("Type \"horizontal\" or \"vertical\" to change drawing style.");
            Console.WriteLine("Type \"exit\" to close the program.");
            Console.WriteLine();

            if (tournament.DoubleElimination)
            {
                Console.WriteLine("Double Elimination");
            }
            else
            {
                Console.WriteLine("Single Elimination");
            }

            Console.WriteLine();

            if (_style == DrawType.Horizontal)
            {
                HorizontalDrawer.DrawTable(tournament);
            }
            else
            {
                VerticalDrawer.DrawTable(tournament);
            }
            Console.WriteLine("Enter your command:");
        }
Exemple #2
0
 public static void Play(TournamentController tournament)
 {
     while (true)
     {
         Display(tournament);
         string command = Console.ReadLine();
         ParseCommand(tournament, command);
     }
 }
Exemple #3
0
        private static void PrintEndForDE(TournamentController tournament, int columnSize, int tour, string mainGridWinner)
        {
            int losersColumnWidthMultiplier = 1;

            if (tour < tournament.Losers.Matches.Length)
            {
                losersColumnWidthMultiplier++;
                PrintMatch(tournament.Players, tournament.Losers.Matches[tour][0], columnSize);
                Console.WriteLine();
                Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize));
                Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize));
                Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize));
                Console.WriteLine();
                Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize));
                Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize * losersColumnWidthMultiplier));
                Console.WriteLine();

                if (tournament.Champion == tournament.Main.Winner)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }

                Console.Write(CenterName(mainGridWinner, (Messenger.MaxChars + 2) * columnSize));
                Console.ResetColor();
            }

            string winnerName = "";

            if (tournament.Losers.Winner > -1)
            {
                winnerName = tournament.Players[tournament.Losers.Winner];
            }

            if (tournament.Champion == tournament.Losers.Winner)
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }

            Console.Write(CenterName(winnerName, (Messenger.MaxChars + 2) * columnSize * losersColumnWidthMultiplier));
            Console.ResetColor();
            Console.WriteLine();
            Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize));
            Console.Write(CenterName("|", (Messenger.MaxChars + 2) * columnSize * losersColumnWidthMultiplier));
            Console.WriteLine();
            Console.WriteLine(CenterName("|", (Messenger.MaxChars + 2) * columnSize * (losersColumnWidthMultiplier + 1)));
            winnerName = "";

            if (tournament.Champion > -1)
            {
                winnerName = tournament.Players[tournament.Champion];
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine(CenterName(winnerName, (Messenger.MaxChars + 2) * columnSize * (losersColumnWidthMultiplier + 1)));
            Console.ResetColor();
        }
        private static void PrintGrid(List <int>[] lines, TournamentController tournament, bool loserGrid)
        {
            for (int k = 0; k < lines.Length; k++)
            {
                for (int i = 0; i < lines[k].Count; i++)
                {
                    PrintCell(tournament, loserGrid, lines, k, i);
                }

                Console.WriteLine();
            }
        }
        private static void PrintCell(TournamentController tournament, bool loserGrid, List <int>[] lines, int line, int column)
        {
            int cell = lines[line][column];

            if (cell != EmptyCellCode)
            {
                if (column > 0)
                {
                    Console.Write('—');
                }
                else
                {
                    Console.Write(' ');
                }

                string playerName = "";

                if (cell > -1)
                {
                    playerName = tournament.Players[cell];
                }

                if (line == lines.Length - 1 || GreenLight(tournament, loserGrid, line, column))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }

                Console.Write(CenterName(playerName, Messenger.MaxChars));
                Console.ResetColor();
                int gridLength = tournament.Main.Matches.Length;

                if (loserGrid)
                {
                    gridLength = tournament.Losers.Matches.Length;
                }

                if (column < gridLength)
                {
                    Console.Write('—');
                }
                else
                {
                    Console.Write(' ');
                }
            }
            else
            {
                Console.Write(CenterName("", (Messenger.MaxChars + 2)));
            }
        }
Exemple #6
0
        private static void ParseCommand(TournamentController tournament, string command)
        {
            char[]   separator = { ' ' };
            string[] words     = command.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            string   warning   = "Invalid command";

            if (words.Length > 0)
            {
                switch (words[0])
                {
                case "play":
                {
                    if (words.Length > 1)
                    {
                        ParsePlay(tournament, words);
                    }

                    break;
                }

                case "vertical":
                {
                    _style = DrawType.Vertical;
                    break;
                }

                case "horizontal":
                {
                    _style = DrawType.Horizontal;
                    break;
                }

                case "exit":
                {
                    Environment.Exit(0);
                    break;
                }

                default:
                {
                    Console.WriteLine(warning);
                    Console.ReadKey();
                    break;
                }
                }
            }
        }
Exemple #7
0
        private static void PrintMatches(TournamentController tournament, int columnSize, int tourCount, int fillerLength)
        {
            for (int i = 0; i < tournament.Main.Matches[tourCount].Length; i++)
            {
                PrintMatch(tournament.Players, tournament.Main.Matches[tourCount][i], columnSize);
            }

            FillLine(fillerLength);

            if (tournament.DoubleElimination)
            {
                for (int i = 0; i < tournament.Losers.Matches[tourCount].Length; i++)
                {
                    PrintMatch(tournament.Players, tournament.Losers.Matches[tourCount][i], columnSize);
                }
            }
        }
Exemple #8
0
        private static string PrintMainWinner(TournamentController tournament, int columnSize)
        {
            string winnerName = "";

            if (tournament.Main.Winner > -1)
            {
                winnerName = tournament.Players[tournament.Main.Winner];
            }

            if (!(tournament.DoubleElimination ^ tournament.Champion == tournament.Main.Winner))
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }

            Console.Write(CenterName(winnerName, (Messenger.MaxChars + 2) * columnSize));
            Console.ResetColor();
            return(winnerName);
        }
Exemple #9
0
        private static void ParsePlay(TournamentController tournament, string[] words)
        {
            string warning = "Invalid command parameters";

            try
            {
                switch (words[1])
                {
                case PlayMain:
                {
                    if (words.Length == 5)
                    {
                        var matchCoords = new MatchInfo(words[2], words[3], words[4]);
                        tournament.PlayGame(matchCoords, false);
                    }
                    else
                    {
                        Console.WriteLine(warning);
                        Console.ReadKey();
                    }
                    break;
                }

                case PlayLosers:
                {
                    if (tournament.DoubleElimination && words.Length == 5)
                    {
                        var matchCoords = new MatchInfo(words[2], words[3], words[4]);
                        tournament.PlayGame(matchCoords, true);
                    }
                    else
                    {
                        Console.WriteLine(warning);
                        Console.ReadKey();
                    }

                    break;
                }

                case PlayFinale:
                {
                    if (tournament.DoubleElimination && words.Length == 3)
                    {
                        tournament.PlayFinale(int.Parse(words[2]) - 1);
                    }
                    else
                    {
                        Console.WriteLine(warning);
                        Console.ReadKey();
                    }

                    break;
                }

                default:
                {
                    Console.WriteLine(warning);
                    Console.ReadKey();
                    break;
                }
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine(warning);
                Console.ReadKey();
            }
            catch (FormatException)
            {
                Console.WriteLine(warning);
                Console.ReadKey();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
            catch (InvalidOperationException e)
            {
                Console.WriteLine(e.Message);
                Console.ReadKey();
            }
        }