コード例 #1
0
ファイル: MethodLibrary.cs プロジェクト: forcebytes/unicorns
        public static int GetUserInt(string prompt, int minNum, int maxNum, string tooLowMessage, string tooHighMessage)
        {
            int  response = 0;
            bool isValid  = false;

            Console.WriteLine(prompt);
            do
            {
                try
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    response = int.Parse(Console.ReadLine());
                    Console.ResetColor();
                    if (response < minNum)
                    {
                        MethodLibrary.WriteInColour(tooLowMessage, ConsoleColor.Red, writeLine: true);
                    }
                    else if (response > maxNum)
                    {
                        MethodLibrary.WriteInColour(tooHighMessage, ConsoleColor.Red, writeLine: true);
                    }
                    else
                    {
                        isValid = true;
                    }
                } // end try
                catch (Exception)
                {
                    MethodLibrary.WriteInColour("That's not a number. Please re-enter.", ConsoleColor.Red, writeLine: true);
                } // end catch
            } while (!isValid);

            return(response);
        } // end method
コード例 #2
0
ファイル: Player.cs プロジェクト: forcebytes/unicorns
        }     // end constructor

        public void DisplayPlayer()
        {
            MethodLibrary.WriteInColour(this.Name, ConsoleColor.Magenta);
            MethodLibrary.WriteInColour($" is a {Type} player. They have ", ConsoleColor.Yellow);
            MethodLibrary.WriteInColour($"{Hand.Count}", ConsoleColor.Magenta);
            MethodLibrary.WriteInColour(" cards in their hand and ", ConsoleColor.Yellow);
            MethodLibrary.WriteInColour($"{Stable.Count}", ConsoleColor.Magenta);
            MethodLibrary.WriteInColour(" in their stable.", ConsoleColor.Yellow, writeLine: true);
        } // end DisplayPlayer
コード例 #3
0
        } // end InitializeNursery()

        private void CheckIfWinner(List <Player> player)
        {
            bool gameOver = false;

            if (player.Count > 5)
            {
                unicornsToWin = 6;
            }

            for (int i = 0; i < player.Count; i++)
            {
                if (player[i].GetNumberOfUnicorns() >= unicornsToWin)
                {
                    gameOver = true;
                    MethodLibrary.WriteInColour("THIS PLAYER HAS WON!", ConsoleColor.Magenta); // add player name.
                } // end if
            } // end for
        } // end CheckIfWinner()
コード例 #4
0
ファイル: MethodLibrary.cs プロジェクト: forcebytes/unicorns
        } // end method

        public static string GetUserChoice(string prompt, string firstChoice, string secondChoice)
        {
            Console.WriteLine(prompt + $" ({firstChoice}/{secondChoice})");
            Console.ForegroundColor = ConsoleColor.Cyan;
            string userResponse = Console.ReadLine();

            Console.ResetColor();

            while (userResponse.ToLower() != firstChoice && userResponse.ToLower() != secondChoice)
            {
                MethodLibrary.WriteInColour("That wasn't a valid choice. Please re-enter.", ConsoleColor.Red, writeLine: true);
                Console.ForegroundColor = ConsoleColor.Cyan;
                userResponse            = Console.ReadLine();
                Console.ResetColor();
            } // end while invalid entry

            return(userResponse);
        } // end GetUserChoice method