コード例 #1
0
ファイル: Program.cs プロジェクト: LSmoka28/CSharpAssessment
        // method to view a speciic weapon and asks to purchase
        static public void ViewAndBuyWeapon(List <Weapon.WeaponStruct> weaponList, List <Weapon.WeaponStruct> myWeaps, int indexNum)
        {
            Weapon.WeaponStruct tmpWeap = weaponList[indexNum - 1];
            Item weapon = new Weapon();

            // prints all values using overriden method
            weapon.ToString(tmpWeap.Name, tmpWeap.Type, tmpWeap.Info, tmpWeap.AttackPwr, tmpWeap.Rarity, tmpWeap.Price);

            // no money in player bank warning
            if (playerBank <= 0)
            {
                playerBank = 0;
                Prompt($"Uh oh! You don't have any units left..\nPlease sell something or come back when you have some more units!");
                return;
            }
            Prompt($"Would you like to buy this weapon? ('y' or 'n')");
            string input = Console.ReadLine().ToLower().Trim();

            if (input == "n")
            {
                return;
            }
            if (input != "y")
            {
                Prompt($"Oops! Looks like you entered and invalid response. \nPlease select your desired weapon and try again\n" +
                       $"*Remember*: \nenter 'y' to buy item\nenter 'n' to decline\n___________________");
                return;
            }
            if (input == "y")
            {
                // check for player having enough units to purchase
                if (playerBank < tmpWeap.Price)
                {
                    Prompt($"Hey! You dont have any enough units left to purchase that!");
                    Prompt($"\nYou have {playerBank} units and this item is {tmpWeap.Price}\n");
                    return;
                }
                else
                {
                    weaponList.Remove(tmpWeap);
                    myWeaps.Add(tmpWeap);

                    playerBank -= tmpWeap.Price;
                    shopBank   += tmpWeap.Price;

                    Prompt($"\nYou now own {tmpWeap.Name}!\n" +
                           $"\nYou currently have {playerBank} units left in your bank\n________________\n");
                    return;
                }
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: LSmoka28/CSharpAssessment
        // method to sell a specific weapon in player inventory
        static public void SellWeap(List <Weapon.WeaponStruct> myWeapInv, List <Weapon.WeaponStruct> weaponList, int indexNum)
        {
            Weapon.WeaponStruct tmpWeap = myWeapInv[indexNum - 1];
            Item weapon = new Weapon();

            // prints all values using overriden method
            weapon.ToString(tmpWeap.Name, tmpWeap.Type, tmpWeap.Info, tmpWeap.AttackPwr, tmpWeap.Rarity, tmpWeap.Price);

            Prompt($"Would you like to sell this item? ('y' or 'n')");
            string input = Console.ReadLine().ToLower().Trim();

            if (input == "n")
            {
                Prompt($"You declined to sell this weapon\n");
                return;
            }
            if (input != "y")
            {
                Prompt($"Oops! Looks like you entered and invalid response. \nPlease try again\n" +
                       $"*Remember*: \nenter 'y' or 'Y' to sell selected item\nenter 'n' or 'N' to decline\n___________________\n");
                return;
            }
            if (input == "y")
            {
                if (shopBank < tmpWeap.Price)
                {
                    Prompt($"Yikes. I dont have enough units to buy that back.");
                    Prompt($"The item is {tmpWeap.Price} units and I have only have {shopBank} units");
                    Prompt($"Sorry! Maybe if you buy something from me, I will have enough units then");
                    return;
                }
                else
                {
                    myWeapInv.Remove(tmpWeap);
                    weaponList.Add(tmpWeap);

                    playerBank += tmpWeap.Price;
                    shopBank   -= tmpWeap.Price;

                    Prompt($"You sold {tmpWeap.Name} for {tmpWeap.Price} units!\n" +
                           $"You now have {playerBank} units in your bank\n___________________\n");
                    Prompt($"The shop bank is now at {shopBank}\n");
                }
            }
        }