ShowNumber() public static méthode

public static ShowNumber ( [ prompt, int min, int max ) : int
prompt [
min int
max int
Résultat int
Exemple #1
0
        static void AddRank(Rank newRank)
        {
            Console.WriteLine();
            Console.WriteLine("Where to position the new rank?");
            TextMenu   menu = new TextMenu();
            TextOption optionTop = menu.AddOption("T", "Top of the hierarchy");
            TextOption optionBottom = menu.AddOption("B", "Bottom of the hierarchy");
            TextOption optionCancel = menu.AddOption("C", "Cancel");
            TextOption optionAbove = null, optionUnder = null;

            if (RankManager.Ranks.Count > 1)
            {
                menu.Column = Column.Right;
                optionAbove = menu.AddOption("O", "Over a specific rank");
                optionUnder = menu.AddOption("U", "Under a specific rank");
            }

            TextOption choice = menu.Show();

            if (choice == optionCancel)
            {
                return;
            }

            if (choice == optionTop)
            {
                RankManager.AddRank(newRank, 0);
            }
            else if (choice == optionBottom)
            {
                RankManager.AddRank(newRank);
            }
            else if (choice == optionAbove)
            {
                int otherRankIndex = TextMenu.ShowNumber("Above which rank?",
                                                         1, RankManager.Ranks.Count);
                if (otherRankIndex == -1)
                {
                    return;
                }
                RankManager.AddRank(newRank, otherRankIndex - 1);
            }
            else if (choice == optionUnder)
            {
                int otherRankIndex = TextMenu.ShowNumber("Under which rank?",
                                                         1, RankManager.Ranks.Count);
                if (otherRankIndex == -1)
                {
                    return;
                }
                RankManager.AddRank(newRank, otherRankIndex);
            }
        }
Exemple #2
0
        static void EraseRank()
        {
            int rankIndexToErase = TextMenu.ShowNumber("Which rank to delete?",
                                                       1, RankManager.Ranks.Count);

            if (rankIndexToErase == -1)
            {
                return;
            }

            Rank rankToErase = RankManager.Ranks[rankIndexToErase - 1];
            Rank subRank;

            if (RankManager.Ranks.Count > 2)
            {
                Console.WriteLine();
                WriteWarning(RankEraseWarning, rankToErase.Name);

                while (true)
                {
                    int substitute = TextMenu.ShowNumber("Substitute rank",
                                                         1, RankManager.Ranks.Count);
                    if (substitute == rankIndexToErase)
                    {
                        Console.WriteLine("Cannot substitute rank with itself; pick a different rank.");
                    }
                    else
                    {
                        subRank = RankManager.Ranks[substitute - 1];
                        break;
                    }
                }
            }
            else
            {
                subRank = rankToErase.NextRankDown ?? rankToErase.NextRankUp;
            }

            if (TextMenu.ShowYesNo("Delete rank {0}, and substitute with {1}?",
                                   rankToErase.Name, subRank.Name))
            {
                RankManager.DeleteRank(rankToErase, subRank);
            }
        }
Exemple #3
0
        static MenuState ShowRanks()
        {
            Refresh("Rank list");

            TextMenu menu = new TextMenu();

            for (int i = 0; i < RankManager.Ranks.Count; i++)
            {
                Rank       rank = RankManager.Ranks[i];
                TextOption derp = menu.AddOption(i + 1,
                                                 rank.Name,
                                                 rank);
                derp.ForeColor = Color.ToConsoleColor(rank.Color);
                if (derp.ForeColor == ConsoleColor.Black)
                {
                    derp.BackColor = ConsoleColor.Gray;
                }
            }

            TextOption optionErase = null, optionRaise = null, optionLower = null;

            menu.Column = Column.Right;
            TextOption optionBack = menu.AddOption("B", "Back to sections");

            menu.AddSpacer();
            TextOption optionAdd  = menu.AddOption("A", "Add rank (blank)");
            TextOption optionCopy = menu.AddOption("C", "Copy existing rank");

            if (RankManager.Ranks.Count > 1)
            {
                optionErase = menu.AddOption("E", "Erase rank");
            }

            if (RankManager.Ranks.Count > 1)
            {
                menu.AddSpacer();
                optionRaise = menu.AddOption("R", "Raise rank in hierarchy");
                optionLower = menu.AddOption("L", "Lower rank in hierarchy");
            }

            menu.AddSpacer();
            TextOption optionDefaults = menu.AddOption("D", "Use defaults");

            TextOption choice = menu.Show();

            if (choice == optionBack)
            {
                return(MenuState.SectionList);
            }
            else if (choice == optionAdd)
            {
                Console.Write("Enter new rank name: ");
                while (true)
                {
                    string rankName = Console.ReadLine();
                    if (Rank.IsValidRankName(rankName))
                    {
                        if (RankManager.FindRank(rankName) != null)
                        {
                            WriteWarning("A rank with this name already exists.");
                        }
                        else
                        {
                            Rank newRank = new Rank(rankName, RankManager.GenerateID());
                            AddRank(newRank);
                            break;
                        }
                    }
                    else
                    {
                        WriteWarning("Rank names must be between 1 and 16 characters long, " +
                                     "and must contain only letters, digits, and underscores.");
                    }
                }
            }
            else if (choice == optionCopy)
            {
                int rankToCopyIndex = TextMenu.ShowNumber("Which rank to copy?",
                                                          1, RankManager.Ranks.Count);
                if (rankToCopyIndex != -1)
                {
                    Console.WriteLine();
                    Rank rankToCopy = RankManager.Ranks[rankToCopyIndex - 1];
                    Console.Write("Enter new rank name: ");
                    while (true)
                    {
                        string rankName = Console.ReadLine();
                        if (Rank.IsValidRankName(rankName))
                        {
                            if (RankManager.FindRank(rankName) != null)
                            {
                                WriteWarning("A rank with this name already exists.");
                            }
                            else
                            {
                                Rank newRank = new Rank(rankName, RankManager.GenerateID(), rankToCopy);
                                AddRank(newRank);
                                break;
                            }
                        }
                        else
                        {
                            WriteWarning("Rank names must be between 1 and 16 characters long, " +
                                         "and must contain only letters, digits, and underscores.");
                        }
                    }
                }
            }
            else if (choice == optionErase)
            {
                EraseRank();
            }
            else if (choice == optionRaise)
            {
                int rankToRaise = TextMenu.ShowNumber("Which rank to raise?",
                                                      2, RankManager.Ranks.Count);
                if (rankToRaise != -1)
                {
                    RankManager.RaiseRank(RankManager.Ranks[rankToRaise - 1]);
                }
            }
            else if (choice == optionLower)
            {
                int rankToLower = TextMenu.ShowNumber("Which rank to lower?",
                                                      1, RankManager.Ranks.Count - 1);
                if (rankToLower != -1)
                {
                    RankManager.LowerRank(RankManager.Ranks[rankToLower - 1]);
                }
            }
            else if (choice == optionDefaults)
            {
                if (TextMenu.ShowYesNo("Reset all ranks to defaults?"))
                {
                    RankManager.ResetToDefaults();
                }
            }
            else
            {
                currentRank = (Rank)choice.Tag;
                return(MenuState.RankDetails);
            }

            return(MenuState.Ranks);
        }