public void start() //uses this to set evrything up before the game starts
        {
            if (File.Exists("playerinv.txt") && File.Exists("shopinv.txt"))
            {
                Load("playerinv.txt");
                Load("shopinv.txt");
            }
            else //if a save file is deleted manulaly by the user the game will load this instead to prevent crashing
            {
                Item potion      = new Potion("Potion", 10, "this will heal you 10HP", 10);
                Item Mastersword = new Weapon("MasterSword", 999, "cant even get this item in the game", 999);
                Item superpotion = new Potion("super potion", 20, "this is better than the potion", 30);
                Item Sword       = new Weapon("Sword", 10, "its a regular sword", 10);

                //shop setup
                shopinv.Add(potion);
                shopinv.Add(Sword);
                shopinv.Add(potion);
                shopinv.Add(superpotion);
                playerinv.Add(potion);
            }

            menu(); //goes to the menu
        }
示例#2
0
        public void Load(string path)
        {
            if (File.Exists(path))
            {
                bool loading = true; //used to make a while loop

                //these are used for loading stuff when the game is reading the save file these values are then used later
                string type;
                string name;
                int    cost;
                int    damage;
                int    heal;
                string description;


                //used to tell which file is loading
                if (path == "playerinv.txt")

                {
                    playerinv.Clear();
                    StreamReader reader = File.OpenText(path);
                    playergold = Convert.ToInt32(reader.ReadLine());
                    while (loading)
                    {
                        type        = reader.ReadLine();
                        name        = reader.ReadLine();
                        cost        = Convert.ToInt32(reader.ReadLine());
                        description = reader.ReadLine();
                        damage      = Convert.ToInt32(reader.ReadLine()); //although it will read the 0 even if its a potion this value does nothing after the if statements
                        heal        = Convert.ToInt32(reader.ReadLine()); //although it will read the 0 even if its a weapon this value does nothing after the if statements
                        if (type == "weapon")
                        {
                            Item weapon = new Weapon(name, cost, description, damage);
                            playerinv.Add(weapon);
                        }
                        if (type == "potion")
                        {
                            Item potion = new Potion(name, cost, description, heal);
                            playerinv.Add(potion);
                        }
                        if (type == null)
                        {
                            loading = false;
                        }
                    }
                    reader.Close();
                }



                if (path == "shopinv.txt")
                {
                    shopinv.Clear();
                    StreamReader reader = File.OpenText(path);
                    shopgold = Convert.ToInt32(reader.ReadLine());
                    while (loading)
                    {
                        type        = reader.ReadLine();
                        name        = reader.ReadLine();
                        cost        = Convert.ToInt32(reader.ReadLine());
                        description = reader.ReadLine();
                        damage      = Convert.ToInt32(reader.ReadLine());
                        heal        = Convert.ToInt32(reader.ReadLine());
                        if (type == "weapon")
                        {
                            Item weapon = new Weapon(name, cost, description, damage);
                            shopinv.Add(weapon);
                        }
                        if (type == "potion")
                        {
                            Item potion = new Potion(name, cost, description, heal);
                            shopinv.Add(potion);
                        }
                        if (type == null)
                        {
                            loading = false;
                        }
                    }
                    reader.Close();
                    Console.Clear();
                    Console.WriteLine("save file loaded");
                    Console.WriteLine("press any key to continue");
                    Console.ReadKey();
                }
            }
            else
            {
                Console.WriteLine("no save file present \n press any key to continue");
                Console.ReadKey();
            }
        }
示例#3
0
        public void superuseradditems() //will allow anyone to create an item in the game
        {
            string itemname         = "";
            int    itemcost         = 0;
            string itemdescript     = "";
            int    itemdamageorheal = 0;

            validchoice = false;
            while (!validchoice)
            {
                Console.Clear();
                Console.WriteLine("what do you want to do");
                Console.WriteLine("1: add item to playerinventory");
                Console.WriteLine("2: add item to shopinventory");
                playerchoice = Console.ReadLine(); //playerchoice 1 is used here for telling which inventory to add the custom item
                if (playerchoice == "1" || playerchoice == "2")
                {
                    validchoice = true;
                }
            }
            validchoice = false;
            while (!validchoice)
            {
                Console.WriteLine("choose item type");
                Console.WriteLine("1: Weapon");
                Console.WriteLine("2: Potion");
                playerchoice2 = Console.ReadLine();     //playerchoice 2 is used for telling the item type

                if (playerchoice2 == "1")
                {
                    validchoice = true;
                }
                if (playerchoice2 == "2")
                {
                    validchoice = true;
                }
            }
            Console.WriteLine("name the item");
            itemname    = Console.ReadLine();
            validchoice = false;
            while (!validchoice)
            {
                Console.WriteLine("how much does it cost to buy this item");
                if (Int32.TryParse(Console.ReadLine(), out itemcost))
                {
                    validchoice = true;
                }
            }
            Console.WriteLine("write a description");
            itemdescript = Console.ReadLine();
            if (playerchoice2 == "1")     //this is for item type weapon
            {
                validchoice = false;
                while (!validchoice)
                {
                    Console.WriteLine("how much damage does the weapon do");
                    if (Int32.TryParse(Console.ReadLine(), out itemdamageorheal))
                    {
                        validchoice = true;
                    }
                }
                Item weapon = new Weapon(itemname, Convert.ToInt32(itemcost), itemdescript, Convert.ToInt32(itemdamageorheal));
                if (playerchoice == "1")
                {
                    playerinv.Add(weapon);
                }
                if (playerchoice == "2")
                {
                    shopinv.Add(weapon);
                }
            }



            if (playerchoice2 == "2")     //this is for item type potion
            {
                validchoice = false;
                while (!validchoice)
                {
                    Console.WriteLine("how much health does the potion heal");

                    if (Int32.TryParse(Console.ReadLine(), out itemdamageorheal))
                    {
                        validchoice = true;
                    }
                }
                Item potion = new Potion(itemname, Convert.ToInt32(itemcost), itemdescript, Convert.ToInt32(itemdamageorheal));
                if (playerchoice == "1")
                {
                    playerinv.Add(potion);
                }
                if (playerchoice == "2")
                {
                    shopinv.Add(potion);
                }
            }
        }