Пример #1
0
        public static void Display(int cursorIndex = 0, string shopMessage = default)
        {
            // Get Player & Shop & Shop assortment
            Player        player    = Program.Player;
            VillageShop   shop      = player.VillagesManager.CurrentVillage.Shop;
            IList <IItem> shopItems = shop.GetAvailableItems();

            // Define menu items
            var menuItems = new Dictionary <string, Action <int> >();

            // Declare menu items
            foreach (IItem item in shopItems)
            {
                string label = $"\"{item.Name}\" for ${NumberConvertor.ShortenNumber(item.PriceForPlayer)} | { item.Amount } left";

                bool added = menuItems.TryAdd(label, (selectedIndex) =>
                {
                    // Check if player has enough money to afford this item
                    double moreMoney = player.MoneyManager.CanAfford(item.PriceForPlayer);

                    // Break if moreMoney > 0, because it means that player has not enough money
                    if (moreMoney > 0)
                    {
                        Display(selectedIndex, $"You need ${ NumberConvertor.ShortenNumber(moreMoney) } more to buy \"{ item.Name }\"");
                    }

                    // Remove item from the shop
                    IItem soldItem = shop.SellItem(item);

                    // Add item to the player's inventory (take money from player)
                    player.BuyItem(soldItem);

                    // Refresh the menu by redrawing -> nonlinear recursion
                    ShopMenu.Display(selectedIndex);
                });

                if (!added)
                {
                    throw new ApplicationException("Item duplication >> VillageShop");
                }
            }

            // Empty shop message
            if (shopItems.Count == 0)
            {
                menuItems.Add("The shop is empty right now", (selectedIndex) => Display(selectedIndex));
            }

            // Add go to menu menu itme
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Process shop message if valid
            if (shopMessage != default)
            {
                menuItems.Add(shopMessage, (selectedIndex) => Display());
            }

            // Display
            (new Menu(menuItems, "BUY IN THE SHOP:", cursorIndex)).Display();
        }
Пример #2
0
    static void Main(String[] args)
    {
        /*------- MarvellousConvertor-----------*/
        int             no;
        NumberConvertor mc;

        Console.Write("Enter the Number: ");
        no = Convert.ToInt32(Console.ReadLine());

        mc = new NumberConvertor(no);
        mc.DisplayBinary();
        mc.DisplayOctal();
        mc.DisplayHexadecimal();


        /*----------- MarvellousString ----------------*/
        string        str;
        StringMethods sm = new StringMethods();

        Console.WriteLine();
        Console.Write("Enter the one Line: ");
        str = Console.ReadLine();
        sm.DisplayLargestWord(str);

        Console.Write("Enter the word to check palindrome or not: ");
        str = Console.ReadLine();
        if (sm.ChkPalindrome(str))
        {
            Console.WriteLine("Word is palindrome");
        }
        else
        {
            Console.WriteLine("Word is not palindrome");
        }
    }
Пример #3
0
        private void HandleHyperlinkClick(Hyperlink sender, HyperlinkClickEventArgs args)
        {
            Hyperlink hyperlink = sender;

            if (hyperlink.FindName("HyperViewerGrid") != null)
            {
                // 현재 표시 중인 HyperViewer 존재시
                Grid        HyperViewerGrid = hyperlink.FindName("HyperViewerGrid") as Grid;
                HyperViewer HyperViewer     = HyperViewerGrid.Parent as HyperViewer;
                int         sup_no;
                if (2 < hyperlink.Inlines.Count)
                {
                    int.TryParse(NumberConvertor.SupToNumber((hyperlink.Inlines[1] as Run).Text), out sup_no);
                }
                else
                {
                    int.TryParse(Regex.Replace((hyperlink.Inlines[0] as Run).Text, "[^0-9.]", ""), out sup_no);
                }

                string target_code = hyperlink.Inlines[hyperlink.Inlines.Count - 1].FontFamily.Source;
                if (target_code == "0")
                {
                    HyperViewer.SearchWords((hyperlink.Inlines[0] as Run).Text);
                }
                else
                {
                    HyperViewer.DisplayWordDetail(target_code, sup_no);
                }
            }
        }
Пример #4
0
        private void DisplayStats()
        {
            /*
             * [] 100       [] 200       [] 100
             */

            // Access player instance
            Player player = Program.Player;

            // Access player's village manager. Cache it since we will use it twice
            PlayerVillage villageManager = player.VillagesManager;

            // Stats Y position
            int posY = ResolutionHandler.GetResolution(1) - 4;

            // Space gap between elements
            string elementsGap = new string(' ', 4);

            // Declare hud elements
            string[] elements =
            {
                $"Money: ${NumberConvertor.ShortenNumber(player.MoneyManager.Money)}",
                $"Protection:  {player.Stats.DefenseProcent}%",
                $"Speed: {player.Stats.MovementSpeed}",
                $"Reputation: {villageManager.GetReputation()}/{villageManager.CurrentVillage.MaxReputation}"
            };

            // string elements =  string.Join(string.Empty, $"", elementsGap, $"🛡️ 4.1%", elementsGap, $"🧑 35/1500");
            // Convert hud elements array to string
            string elementsString = string.Join(new string(' ', 8), elements);

            // Calculate position (center)
            int posX = ResolutionHandler.GetResolution(0) / 2 - elementsString.Length / 2;

            // Set cursor position
            Console.SetCursorPosition(posX, posY);

            // Output
            Console.WriteLine(elementsString);
        }
Пример #5
0
        public static void Display(int cursorIndex = 0)
        {
            // Access player & playerInventory
            Player          player          = Program.Player;
            PlayerInventory playerInventory = player.Inventory;
            Village         playerVillage   = player.VillagesManager.CurrentVillage;

            // Define menu items dictionary
            var menuItems = new Dictionary <string, Action <int> >();

            // Get inventory items
            IList <IItem> inventoryItems = playerInventory.Items;

            // Add items
            foreach (IItem item in inventoryItems)
            {
                // Add equip option
                if (item is IEquipable equipableItem)
                {
                    // Check if item is already equiped. Prepare for unequip action if yes
                    bool doEquip = !equipableItem.IsEquipedOn(playerInventory);

                    // Action label
                    string equipText = (doEquip) ? "Equip" : "Unequip";

                    // Add option to the menu
                    menuItems.Add($"{ equipText } \"{ item.Name }\"", (selectedIndex) =>
                    {
                        // Equip/Unequip
                        if (doEquip)
                        {
                            equipableItem.EquipOn(playerInventory);
                        }
                        else
                        {
                            equipableItem.UnequipOn(playerInventory);
                        }

                        // Refresh menu
                        Display(selectedIndex);
                    });
                }
                else if (item is IUseable useableItem)
                { // Add apply {buff} option
                    menuItems.Add($"Use \"{ item.Name }\" | You have { item.Amount }", (selectedIndex) =>
                    {
                        // Remove item from the player's inventory
                        player.Inventory.RemoveItem(item);

                        // Apply item's effects on player
                        useableItem.UseOn(player);

                        // Refresh menu
                        Display(selectedIndex);
                    });
                }

                // Add sell option
                menuItems.Add($"Sell \"{ item.Name }\" for ${ NumberConvertor.ShortenNumber(item.SellPriceForPlayer) } | You have { item.Amount }", (selectedIndex) =>
                {
                    player.SellItem(item);

                    // Refresh menu
                    Display(selectedIndex);
                });
            }

            // Add empty inventory status
            if (inventoryItems.Count == 0)
            {
                menuItems.Add("Your inventory is empty", Display);
            }

            // Add "back to menu" button
            menuItems.Add("> Go to menu <", (selectedIndex) => ActionGroupsMenu.Display());

            // Display
            (new Menu(menuItems, "INVENTORY ACTIONS:", cursorIndex)).Display();
        }