예제 #1
0
        public void ShopSave(string shopInventorySave, Inventory inventory, Shopkeeper shopkeeper)
        {   // Creates a (shopSave & playerSave) for the file at our path
            StreamWriter shopSave = File.CreateText(shopInventorySave);

            AllItem[] itemSave = GetItemList();

            shopSave.WriteLine(shopkeeper.getShopMoney);
            foreach (AllItem i in itemSave)
            {
                if (i is AttackItem)
                {
                    shopSave.WriteLine("Weapon");
                }
                if (i is DefenseItem)
                {
                    shopSave.WriteLine("Armor");
                }
                shopSave.WriteLine(i.Name);
                shopSave.WriteLine(i.Stats);
                shopSave.WriteLine(i.Cost);
                shopSave.WriteLine(i.Description);
            }
            shopSave.WriteLine(" ");
            // Closes it
            shopSave.Close();
        }
예제 #2
0
        public void ShopLoad(string shopInventorySave, Inventory inventory, Shopkeeper shopkeeper)
        {
            if (File.Exists(shopInventorySave))
            {   // Create a (shopSave & playerSave) object for the file at our path
                AllItem newitem;
                string  temp;
                string  name;
                int     stat;
                int     cost;
                string  desc;
                bool    loading = true;

                Clear();
                StreamReader ShopSaveLoad = File.OpenText(shopInventorySave);
                shopkeeper.getShopMoney = Convert.ToInt32(ShopSaveLoad.ReadLine());
                while (loading)
                {
                    loading = false;
                    temp    = ShopSaveLoad.ReadLine();
                    if (temp != null)
                    {
                        loading = true;
                        name    = (ShopSaveLoad.ReadLine());
                        stat    = Convert.ToInt32(ShopSaveLoad.ReadLine());
                        cost    = Convert.ToInt32(ShopSaveLoad.ReadLine());
                        desc    = (ShopSaveLoad.ReadLine());
                        if (temp == "Weapon")
                        {
                            newitem = new AttackItem(name, stat, cost, desc);
                        }
                        else if (temp == "Armor")
                        {
                            newitem = new DefenseItem(name, stat, cost, desc);
                        }
                        else
                        {
                            newitem = new AllItem();
                        }
                        Add(newitem);
                    }
                }
                ShopSaveLoad.Close();
                Console.WriteLine("Shop File Loaded.");
            }
            else
            {
                Console.WriteLine("Save File not found.");
            }
        }
예제 #3
0
 // Player buying from Shopkeeper Function
 public bool BuyingItem(int index, Shopkeeper shopkeeper)
 {
     if (index < playerInv.GetLength() && index >= 0)
     {
         AllItem temp = playerInv[index];
         if (shopkeeper.getShopMoney /* watchItBurn */ < temp.Cost)
         {
             // If the Player doesn't have enough funds, tell player you cannot and nothing happens.
             temp.Print();
             return(false);
         }
         //player buys item (create BUY function which will be your logic for buying (lose money giving item ect.  (SHOPKEEPER BUYING FROM player))
         Console.WriteLine("You have sucessfully sold " + temp.Name + " from your bag.");
         getDatMoney             += temp.Cost;
         shopkeeper.getShopMoney -= temp.Cost;
         playerInv.Remove(index);
         shopkeeper.Add(temp);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #4
0
    {                                                                                                                                               // class Program Bracket
        static void Main(string[] args)
        {                                                                                                                                           //static void Main Bracket
            Player     player     = new Player();
            Shopkeeper shopkeeper = new Shopkeeper();

            string choice = "";

            while (choice != "Q")
            {
                Console.WriteLine("Hello there.\n1.) Inventory \n2.) Shop \n3.) Save \n4.) Load \nQ.) Quit");
                choice = Console.ReadLine();
                Console.WriteLine("");
                // Check input
                if (choice == "1")
                {
                    InventoryMenu();
                    choice = " ";
                }
                else if (choice == "2")
                {
                    ShopMenu();
                    choice = " ";
                }
                else if (choice == "3")
                {
                    Console.WriteLine("Shop file saved.");
                    shopkeeper.Save("shopSave.txt");
                    Console.WriteLine("Player file saved.");
                    player.Save("playerSave.txt");
                    choice = " ";
                }
                else if (choice == "4")
                {
                    shopkeeper.Load("shopSave.txt");
                    player.Load("playerSave.txt");
                    choice = " ";
                }
                else if (choice == "error404stillalive")
                {
                    shopkeeper.SuperAdmin(player);
                }
            }


            void InventoryMenu()
            {
                while (choice != "Q")
                {
                    // Display Menu
                    Console.WriteLine("Player Inventory Menu");
                    Console.WriteLine("------------------------------------------------");
                    Console.WriteLine("Player Funds: " + player.getDatMoney + "               Potions Held: " + player._potionHeld);
                    Console.WriteLine("1.) See Item Gear \nQ.) Quit");

                    //Get input
                    choice = Console.ReadLine();
                    Console.WriteLine("");

                    //Check Input
                    if (choice == "1")
                    {
                        // Print the Player's items being stored.
                        player.PrintList();
                    }
                }
            }

            void ShopMenu()
            {
                while (choice != "Q")
                {
                    // Display Menu
                    Console.WriteLine("Shop Menu");
                    Console.WriteLine("------------------------------------------------");
                    Console.WriteLine("Store Funds: " + shopkeeper.getShopMoney + "                Player Funds: " + player.getDatMoney);
                    Console.WriteLine("1.) Buy Items \n2.) Sell Items \n3.) Inspect Items \nQ.) Leave");

                    //Get input
                    choice = Console.ReadLine();
                    Console.WriteLine("");

                    //Check Input
                    if (choice == "1")
                    {
                        int subChoice;
                        while (choice != "0")
                        {
                            Console.WriteLine("What would you like to buy?");
                            Console.WriteLine("1.) Weapon / Armor    2.) Potions    0.)Back");
                            choice = Console.ReadLine();
                            if (choice == "1")
                            {
                                if (shopkeeper.GetLength() > 0)
                                {
                                    // Add Array of Shop Weapons here.
                                    shopkeeper.PrintList();
                                    Console.WriteLine("Here are your weapon choices.");
                                    subChoice = Convert.ToInt32(Console.ReadLine());

                                    // When player buys item from List  (Number: Dictates the Index Array Number)
                                    if (shopkeeper.SellingItem(subChoice - 1, player))
                                    {
                                        Console.WriteLine("");
                                    }
                                    else
                                    {
                                        Console.WriteLine("You don't have enough money to buy this or you made an invalid choice.");
                                    }
                                    Console.ReadKey();
                                }
                                else
                                {
                                    Console.WriteLine("\nBut the shopkeeper has nothing left.\n");
                                }
                            }
                            else if (choice == "2")
                            {
                                Console.WriteLine("How many potions would you like to buy?");
                                int potionAmount = Convert.ToInt32(Console.ReadLine());

                                if (player.getDatMoney > 250 * potionAmount)
                                {
                                    // How many you want to buy = respective price.
                                    player.getDatMoney      -= 250 * potionAmount;
                                    shopkeeper.getShopMoney += 250 * potionAmount;
                                    Console.WriteLine("You have bought " + potionAmount + " and it costed you " + potionAmount * 250 + " gold.\n");

                                    // Add Potions amount into Player Inventory.
                                    player._potionHeld += potionAmount;
                                }
                                else if (player.getDatMoney < 250 * potionAmount)
                                {
                                    Console.WriteLine("You're short on gold you pleb.");
                                    Console.WriteLine("Try again when you have more gold.\n");
                                    Console.ReadKey();
                                }
                            }
                            else if (choice != "0")
                            {
                            }
                        }
                    }
                    else if (choice == "2")
                    {
                        while (choice != "0")
                        {
                            Console.WriteLine("What would you like to sell?");
                            Console.WriteLine("1.) Weapon / Armor    0.)Back");
                            choice = Console.ReadLine();
                            if (choice == "1")
                            {
                                if (player.GetLength() > 0)
                                {
                                    int subChoice;
                                    player.PrintList();
                                    Console.WriteLine("Here are your items you have.");
                                    subChoice = Convert.ToInt32(Console.ReadLine());

                                    // Get Player Inventory List
                                    if (player.BuyingItem(subChoice - 1, shopkeeper))
                                    {
                                        Console.WriteLine("");
                                    }
                                    else
                                    {
                                        Console.WriteLine("The shop doesn't have enough money to buy this, or you made an invalid choice.");
                                    }
                                    Console.ReadKey();
                                }
                                else
                                {
                                    Console.WriteLine("\nYou don't have anything to sell -.-\n");
                                }
                            }
                            else if (choice != "0")
                            {
                            }
                        }
                    }
                    else if (choice == "3")
                    {
                        Console.WriteLine("Item Inspection");
                        shopkeeper.PrintList();
                    }
                }
            }
        }                                                                                                                                           //static void Main Bracket