Пример #1
0
        void RenderAlphabetically()
        {
            Console.Clear();
            var sortedAlphabetically = playerList.OrderBy(p => p.Value.Name).Select(p => p.Value);

            Console.WriteLine("Seznam hráčů seřazených podle abecedy: ");
            Console.WriteLine();
            int order = 1;

            foreach (var item in sortedAlphabetically)
            {
                if (item.PointList.Count > 0)
                {
                    Console.WriteLine($"{order}: {item.Name}, nejvyšší počet získaných bodů: {item.PointList.Max()}");
                }
                else
                {
                    Console.WriteLine($"{order}: {item.Name}, ještě nehrál(a)");
                }
                order++;
            }

            Console.WriteLine();
            Console.WriteLine("A co dál?");
            Console.WriteLine("Pokračovat v prozkoumávání výsledků - stikněte 1");
            Console.WriteLine("Ukončit hru - stiskněte 2");
            Console.WriteLine("Začít novou hru - stiskněte 3");

            ChoiceMaking choiceAfterExploring = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => ExploreResults() }, { 2, () => Environment.Exit(0) }, { 3, () => { loadPlayerFromFile(); Initialisation(); } }
            });

            choiceAfterExploring.Choose();
        }
Пример #2
0
        void RenderSpecificPlayer()
        {
            Console.Clear();
            Console.WriteLine("Zadejte jméno hráče, kterého hledáte:");
            bool nameEntered = false;

            do
            {
                string name = Console.ReadLine();
                if (String.IsNullOrWhiteSpace(name))
                {
                    Console.WriteLine("Tohle není jméno. Zadejte jméno s platnými znaky:");
                }
                else
                {
                    var chosenPlayer = playerList.Where(p => p.Value.Name == name).Select(p => p.Value).ToList();
                    if (chosenPlayer.Count == 0)
                    {
                        Console.WriteLine("Bohužel, toto jméno v seznamu hráčů neexistuje. Zadejte jiné jméno:");
                    }
                    else
                    {
                        nameEntered = true;
                        Console.WriteLine();
                        foreach (var item in chosenPlayer)
                        {
                            if (item.PointList.Count > 0)
                            {
                                Console.WriteLine($"Hráč \"{item.Name}\", nejvyšší počet získaných bodů: {item.PointList.Max()}");
                            }
                            else
                            {
                                Console.WriteLine($"Hráč \"{item.Name}\", ještě nehrál(a)");
                            }
                        }
                    }
                }
            } while (!nameEntered);

            Console.WriteLine();
            Console.WriteLine("A co dál?");
            Console.WriteLine("Pokračovat v prozkoumávání výsledků - stikněte 1");
            Console.WriteLine("Ukončit hru - stiskněte 2");
            Console.WriteLine("Začít novou hru - stiskněte 3");

            ChoiceMaking choiceAfterExploring = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => ExploreResults() }, { 2, () => Environment.Exit(0) }, { 3, () => { loadPlayerFromFile(); Initialisation(); } }
            });

            choiceAfterExploring.Choose();
        }
Пример #3
0
        void RenderBestThree()
        {
            Console.Clear();

            //a subdictionary is created, into which only player with some results are copied:
            Dictionary <int, Player> subPlayerList = new Dictionary <int, Player>();

            foreach (KeyValuePair <int, Player> item in playerList)
            {
                if (item.Value.PointList.Count > 0)
                {
                    subPlayerList.Add(item.Key, item.Value);
                }
            }


            //take 3 best, unless there are less than 3 players with results:
            int numberOfBest = 3;

            if (subPlayerList.Count < 3)
            {
                numberOfBest = subPlayerList.Count;
            }

            var bestthree = subPlayerList.OrderByDescending(p => p.Value.PointList.Max()).Take(numberOfBest).Select(p => p.Value);

            Console.WriteLine("První tři nejlepší: ");
            int order = 1;

            foreach (var item in bestthree)
            {
                Console.WriteLine($"{order}: {item.Name}, nejvyšší počet získaných bodů: {item.PointList.Max()}");
                order++;
            }
            if (numberOfBest < 3)
            {
                Console.WriteLine("(Ostatní ještě nehráli.)");
            }
            Console.WriteLine();
            Console.WriteLine("A co dál?");
            Console.WriteLine("Pokračovat v prozkoumávání výsledků - stikněte 1");
            Console.WriteLine("Ukončit hru - stiskněte 2");
            Console.WriteLine("Začít novou hru - stiskněte 3");

            ChoiceMaking choiceAfterExploring = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => ExploreResults() }, { 2, () => Environment.Exit(0) }, { 3, () => { loadPlayerFromFile(); Initialisation(); } }
            });

            choiceAfterExploring.Choose();
        }
Пример #4
0
        void ChoosePlayer()
        {
            ChoiceMaking playerChoice = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => EnterPlayerName() }, { 2, () => { if (playerList != null)
                                                             {
                                                                 ChoosePlayerFromList();
                                                             }
                                                             else
                                                             {
                                                                 Console.WriteLine("Bohužel, seznam hráčů je prázdný. Stiskněte 1 a založte si nového hráče."); ChoosePlayer();
                                                             } } }
            });

            playerChoice.Choose();
        }
Пример #5
0
        void ExploreResults()
        {
            Console.Clear();
            Console.WriteLine("Pojďme prozkoumat výsledky hráčů.");
            Console.WriteLine();
            Console.WriteLine("Vypsat první tři hráče s nejvyšším skóre: stiskněte 1");
            Console.WriteLine("Vyhledat konkrétního hráče dle jména: stiskněte 2");
            Console.WriteLine("Vypsat všechny hráče podle abecedy: stiskněte 3");
            Console.WriteLine("Vypsat všechny hráče podle nejvyššího počtu získaných bodů: stiskněte 4");

            ChoiceMaking exploreChoice = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => RenderBestThree() }, { 2, () => RenderSpecificPlayer() }, { 3, () => RenderAlphabetically() }, { 4, () => RenderFromTheBest() }
            });

            exploreChoice.Choose();
        }
Пример #6
0
        void RenderFromTheBest()
        {
            Console.Clear();

            //a subdictionary is created, into which only player with some results are copied:
            Dictionary <int, Player> subPlayerList = new Dictionary <int, Player>();

            foreach (KeyValuePair <int, Player> item in playerList)
            {
                if (item.Value.PointList.Count > 0)
                {
                    subPlayerList.Add(item.Key, item.Value);
                }
            }

            var sortedByBest = subPlayerList.OrderByDescending(p => p.Value.PointList.Max()).Select(p => p.Value);

            Console.WriteLine("Seznam hráčů seřazených podle nejlepších výsledků: ");
            Console.WriteLine();
            int order = 1;

            foreach (var item in sortedByBest)
            {
                Console.WriteLine($"{order}: {item.Name}, nejvyšší počet získaných bodů: {item.PointList.Max()}");
                order++;
            }
            if (subPlayerList.Count < playerList.Count)
            {
                Console.WriteLine("(Ostatní ještě nehráli.)");
            }
            Console.WriteLine();
            Console.WriteLine("A co dál?");
            Console.WriteLine("Pokračovat v prozkoumávání výsledků - stikněte 1");
            Console.WriteLine("Ukončit hru - stiskněte 2");
            Console.WriteLine("Začít novou hru - stiskněte 3");

            ChoiceMaking choiceAfterExploring = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => ExploreResults() }, { 2, () => Environment.Exit(0) }, { 3, () => { loadPlayerFromFile(); Initialisation(); } }
            });

            choiceAfterExploring.Choose();
        }
Пример #7
0
        void EndOfGame(int score)
        {
            string finalPhrase = "";
            string points      = "";

            if (score == 1)
            {
                points = "bod";
            }
            else if (score == 0 || score > 4)
            {
                points = "bodů";
            }
            else if (score > 1 && score < 5)
            {
                points = "body";
            }

            if (player.Life == 0)
            {
                finalPhrase = "Zranění neslučitelné s životem, konec hry! Vaše skóre: " + score + " " + points;
            }
            else if (player.NumberOfBullets == 0)
            {
                finalPhrase = "Došly náboje, konec hry! Vaše skóre: " + score + " " + points;
            }
            string question = "Co chcete udělat teď?";
            string choice1  = "Dát si další hru: stiskněte 1";
            string choice2  = "Ukončit hru: stiskněte 2";
            string choice3  = "Zobrazit výsledky hráčů: stiskněte 3";

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.BackgroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition((Width - finalPhrase.Length) / 2, Height / 2);
            Console.WriteLine(finalPhrase);
            Console.ResetColor();

            Console.SetCursorPosition((Width - question.Length) / 2, (Height / 2) + 2);
            Console.WriteLine(question);
            Console.SetCursorPosition((Width - choice1.Length) / 2, (Height / 2) + 4);
            Console.WriteLine(choice1);
            Console.SetCursorPosition((Width - choice2.Length) / 2, (Height / 2) + 5);
            Console.WriteLine(choice2);
            Console.SetCursorPosition((Width - choice3.Length) / 2, (Height / 2) + 6);
            Console.WriteLine(choice3);
            Console.SetCursorPosition(Width - 12, Height);
            Console.Write("Životy: " + player.Life);

            if (player.Life == 0)
            {
                Console.SetCursorPosition(player.X - 2, player.Y);
                Console.Write("  (x.x)  ");
            }
            else if (player.NumberOfBullets == 0)
            {
                Console.SetCursorPosition(player.X - 2, player.Y);
                Console.Write("  (°.°)  ");
            }

            Console.SetCursorPosition(Width / 2, (Height / 2) + 7);
            Console.WriteLine(" ");
            Console.SetCursorPosition(Width / 2, (Height / 2) + 7);

            ChoiceMaking choiceEndOfGame = new ChoiceMaking(new Dictionary <int, Action>()
            {
                { 1, () => { loadPlayerFromFile(); Initialisation(); } }, { 2, () => Environment.Exit(0) }, { 3, () => ExploreResults() }
            });

            choiceEndOfGame.Choose();
        }