Inventory/Equipped Items Text Based RPG

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 2822 Views - Last Post: 10 August 2013 - 07:22 AM Rate Topic: ***** 1 Votes

#1 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Inventory/Equipped Items Text Based RPG

Posted 04 August 2013 - 07:42 PM

Hello everyone, I'm a new member here and I've run into quite a snag. I'm posting the itemization/equipped items/inventory question in this one post. I have approximately two other topics that I need help on but I'll post on those later to avoid this getting more bloated than it already will be. Hang on, this will get long.

First, a little background. I've recently graduated high school and I'm about to begin my education in Computer Science. in high school, I learned C# and coded a full text based rpg, and now I want to create a sequel. My problem lies in the fact that I want the second game to be bigger and better than the first in a few ways. Firstly, I want a real inventory system in the game with real items and real gear. In my first game, I had a system that went something like:

You have main stats (health, maxHealth, armor, attack, maxAttack, etc), and then bonus stats. Gear wouldn't be gear, and there was no inventory. There's just bonus stats that get applied to the main stats. Here's an excerpt from my write up on the game:

"The Itemization


Ah, itemization. A crucial part to any RPG on the market (free or paid for). The itemization in The Chronicles of Asku: The Risen is relatively simple, but enough to keep the player engaged in the game for a nice amount of time. All mobs will drop a currency called gold. This gold has a few uses, one of them being buying armor and weapons in the shop. Every 5 levels, a new set of items is unlocked. For example, once I hit level 15 on a character, I can buy the level 15-19 armor set. This includes a sword which increases my attack points (the first option on the battle menu). A staff which increases my magic attacks (the second battle option). An amulet which increases my character's total health. A healing tome which increases the healing output of my character (the third battle option). Lastly (though its listed first in the store) is armor. Armor reduces incoming damage. If you'll bear with me, I'll list my damage formula for mobs: mobDamage = mobDamage - (myHero.armor * .10) ... What does this mean? The mob's damage is a random number from its base damage range, and then 10% of your armor value is subtracted from the mob's damage. Here's an example: Suppose the mob's randomly generated damage is 5000, and your armor is 200. This means mobDamage = 5000 - (200 * .1). so mobDamage = 4980. So your character comes out taking 20 less damage than they would if they had no armor at all. So when your character has a high enough armor value, it may prove to be useful (the highest armor value in the game is 22,000).

Now, I mentioned that for receiving items the store as being one route, however, it doesn't yield the best armor for a level range. Killing bosses will yield the best items. During the leveling game, (King Drake's Tomb), the bosses have a 1/5 (20%) chance of dropping each specific item. That means the first time you kill that boss, he's guaranteed to drop a piece that you can use (unless you already have better items from later in the game). However, by the time you're going for the last piece of gear, there's a 4/5 chance he'll drop something that you already have (80%) chance. This means that for each piece of gear you receive, it becomes less likely that you'll receive your next needed piece. This is to give a sense of immediate reward and progression, while prolonging the time needed by each new piece. This ensures that the game isn't readily tossed aside as quickly, while at the same time rewarding the player."

This is to show stats relevant to the discussion.
class Hero : Character
    {
        public int armor = 5;
        public int baseArmor = 5;
        public int health = 20;
        public int baseHealth = 20;
        public int maxHealth = 20;
        public int baseMinHeal = 1;
        public int baseMaxHeal = 7;
        public int baseMinAttack =1;
        public int baseMaxAttack = 11;
        public int baseMinMagic = 1;
        public int baseMaxMagic = 11;
        public int minHeal = 1;
        public int maxHeal = 7;
        public int minAttack = 1;
        public int maxAttack = 11;
        public int minMagic = 1;
        public int maxMagic = 11;
        public int attackBonus = 0;
        public int healthBonus = 0;
        public int magicBonus = 0;
        public int healBonus = 0;
        public int armorBonus = 0;



This snippet has two purposes. First is to show how I apply the "bonus stats" to "main stats" on level ups.
class CalcHeroLevel
    {
        Hero myHero = new Hero();

        public void GetPlayerLevel(Hero myHero)
        {
            if (myHero.xp >= 0 && myHero.xp < 20) //Player level 1
            {
                myHero.level = 1;
            }

            else if (myHero.xp >= 20 && myHero.xp < 100) //Player level 2
            {
                myHero.level = 2;

                myHero.baseArmor = 15;
                myHero.baseHealth = 25;
                myHero.baseMaxAttack = 16;
                myHero.baseMinAttack = 5;
                myHero.baseMinHeal = 5;
                myHero.baseMaxHeal = 16;
                myHero.baseMinMagic = 5;
                myHero.baseMaxMagic = 16;

                myHero.armor = myHero.baseArmor + myHero.armorBonus;
                myHero.health = myHero.baseHealth + myHero.healthBonus;
                myHero.maxHealth = myHero.baseHealth + myHero.healthBonus;
                myHero.maxAttack = myHero.baseMaxAttack + myHero.attackBonus;
                myHero.minAttack = myHero.baseMinAttack + myHero.attackBonus;
                myHero.minHeal = myHero.baseMinHeal + myHero.healBonus;
                myHero.maxHeal = myHero.baseMaxHeal + myHero.healBonus;
                myHero.minMagic = myHero.baseMinMagic + myHero.magicBonus;
                myHero.maxMagic = myHero.baseMaxMagic + myHero.magicBonus;
            }




This last set of code has to do with buying "armor" from the shop, and your bonus stats get replaced with the store armors bonus stats
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using The_Chronicles_of_Asku.Characters;
using The_Chronicles_of_Asku.Areas.Resources;

namespace The_Chronicles_of_Asku
{
    class Shop
    {
        public void Store(Hero myHero)
        {
            string answer;
            do
            {
                if (myHero.level >= 1 && myHero.level <= 4)
                {
                    OneToFour(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 5 && myHero.level <= 9)
                {
                    FiveToNine(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 10 && myHero.level <= 14)
                {
                    TenToFourteen(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 15 && myHero.level <= 19)
                {
                    FifteenToNineTeen(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 20 && myHero.level <= 24)
                {
                    Twenty(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 25 && myHero.level <= 29)
                {
                    TwentyFive(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 30 && myHero.level <= 34)
                {
                    Thirty(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 35 && myHero.level <= 39)
                {
                    ThirtyFive(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 40 && myHero.level <= 44)
                {
                    Forty(myHero);
                    ClearScreen();
                }
                else if (myHero.level >= 45 && myHero.level <= 49)
                {
                    FortyFive(myHero);
                    ClearScreen();
                }
                else if (myHero.level == 50)
                {
                    Fifty(myHero);
                    ClearScreen();
                }
                Console.WriteLine("Do you want to shop some more today? (1) Yes, (2) No");
                answer = Console.ReadLine();
                Console.Clear();
            } while (answer == "1");
            
        }

        private void OneToFour(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 2 Armor - 10 gold
2. Sword - 5 Damage - 10 gold
3. Staff - 5 Magic - 10 gold
4. Amulet - 5 Health - 10 gold
5. Healing Tome - 5 Healing -10 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 10)
                    {
                        myHero.gold -= 10;
                        myHero.armorBonus = 2;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 10 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 10)
                    {
                        myHero.gold -= 10;
                        myHero.attackBonus = 5;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 10 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 10)
                    {
                        myHero.gold -= 10;
                        myHero.magicBonus = 5;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 10 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 10)
                    {
                        myHero.gold -= 10;
                        myHero.healthBonus = 5;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 10 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 10)
                    {
                        myHero.gold -= 10;
                        myHero.healBonus = 5;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 10 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
            
        }

        private void FiveToNine(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 4 Armor - 20 gold
2. Sword - 10 Damage - 20 gold
3. Staff - 10 Magic - 20 gold
4. Amulet - 10 Health -20 gold
5. Healing Tome - 10 Healing -20 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 20)
                    {
                        myHero.gold -= 20;
                        myHero.armorBonus = 5;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 20 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 20)
                    {
                        myHero.gold -= 20;
                        myHero.attackBonus = 10;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 20 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 20)
                    {
                        myHero.gold -= 20;
                        myHero.magicBonus = 10;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 20 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 20)
                    {
                        myHero.gold -= 20;
                        myHero.healthBonus = 10;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 20 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 20)
                    {
                        myHero.gold -= 20;
                        myHero.healBonus = 10;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 20 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void TenToFourteen(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 8 Armor - 40 gold
2. Sword - 15 Damage - 40 gold
3. Staff - 15 Magic - 40 gold
4. Amulet - 35 Health - 40 gold
5. Healing Tome - 30 Healing - 40 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 40)
                    {
                        myHero.gold -= 40;
                        myHero.armorBonus = 8;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 40 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 40)
                    {
                        myHero.gold -= 40;
                        myHero.attackBonus = 15;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 40 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 40)
                    {
                        myHero.gold -= 40;
                        myHero.magicBonus = 15;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 40 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 40)
                    {
                        myHero.gold -= 40;
                        myHero.healthBonus = 30;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 40 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 40)
                    {
                        myHero.gold -= 40;
                        myHero.healBonus = 35;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 40 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }

                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void FifteenToNineTeen(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 14 Armor -100 gold
2. Sword - 45 Damage -100 gold
3. Staff - 45 Magic -100 gold
4. Amulet - 45 Health -100 gold
5. Healing Tome - 45 Healing -100 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 100)
                    {
                        myHero.gold -= 100;
                        myHero.armorBonus = 14;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 100 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 100)
                    {
                        myHero.gold -= 100;
                        myHero.attackBonus = 45;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 100 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 100)
                    {
                        myHero.gold -= 100;
                        myHero.magicBonus = 45;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 100 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 100)
                    {
                        myHero.gold -= 100;
                        myHero.healthBonus = 45;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 100 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 100)
                    {
                        myHero.gold -= 100;
                        myHero.healBonus = 45;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 100 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void Twenty(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 20 Armor -500 gold
2. Sword - 100 Damage -500 gold
3. Staff - 100 Magic -500 gold
4. Amulet - 100 Health -500 gold
5. Healing Tome - 100 Healing -500 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 500)
                    {
                        myHero.gold -= 500;
                        myHero.armorBonus = 20;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 500)
                    {
                        myHero.gold -= 500;
                        myHero.attackBonus = 100;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 500)
                    {
                        myHero.gold -= 500;
                        myHero.magicBonus = 100;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 500)
                    {
                        myHero.gold -= 500;
                        myHero.healthBonus = 100;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 500)
                    {
                        myHero.gold -= 500;
                        myHero.healBonus = 100;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void TwentyFive(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 30 Armor -1500 gold
2. Sword - 150 Damage -1500 gold
3. Staff - 150 Magic -1500 gold
4. Amulet - 150 Health -1500 gold
5. Healing Tome - 150 Healing -1500 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 1500)
                    {
                        myHero.gold -= 1500;
                        myHero.armorBonus = 30;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 1500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 1500)
                    {
                        myHero.gold -= 1500;
                        myHero.attackBonus = 150;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 1500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 1500)
                    {
                        myHero.gold -= 1500;
                        myHero.magicBonus = 150;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 1500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 1500)
                    {
                        myHero.gold -= 1500;
                        myHero.healthBonus = 150;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 1500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 1500)
                    {
                        myHero.gold -= 1500;
                        myHero.healBonus = 150;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 1500 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void Thirty(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 40 Armor -4000 gold
2. Sword - 200 Damage -4000 gold
3. Staff - 200 Magic -4000 gold
4. Amulet - 200 Health -4000 gold
5. Healing Tome - 200 Healing -4000 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 4000)
                    {
                        myHero.gold -= 4000;
                        myHero.armorBonus = 40;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 4000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 4000)
                    {
                        myHero.gold -= 4000;
                        myHero.attackBonus = 200;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 4000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 4000)
                    {
                        myHero.gold -= 4000;
                        myHero.magicBonus = 200;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 4000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 4000)
                    {
                        myHero.gold -= 4000;
                        myHero.healthBonus = 200;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 4000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 4000)
                    {
                        myHero.gold -= 4000;
                        myHero.healBonus = 200;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 4000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void ThirtyFive(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 60 Armor -8000 gold
2. Sword - 300 Damage -8000 gold
3. Staff - 300 Magic -8000 gold
4. Amulet - 300 Health -8000 gold
5. Healing Tome - 300 Healing -8000 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 8000)
                    {
                        myHero.gold -= 8000;
                        myHero.armorBonus = 60;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 8000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 8000)
                    {
                        myHero.gold -= 8000;
                        myHero.attackBonus = 300;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 8000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 8000)
                    {
                        myHero.gold -= 8000;
                        myHero.magicBonus = 300;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 8000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 8000)
                    {
                        myHero.gold -= 8000;
                        myHero.healthBonus = 300;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 8000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 8000)
                    {
                        myHero.gold -= 8000;
                        myHero.healBonus = 300;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 8000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void Forty(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 80 Armor -10000 gold
2. Sword - 400 Damage -10000 gold
3. Staff - 400 Magic -10000 gold
4. Amulet - 400 Health -10000 gold
5. Healing Tome - 400 Healing -10000 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 10000)
                    {
                        myHero.gold -= 10000;
                        myHero.armorBonus = 80;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 10000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 10000)
                    {
                        myHero.gold -= 10000;
                        myHero.attackBonus = 400;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 10000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 10000)
                    {
                        myHero.gold -= 10000;
                        myHero.magicBonus = 400;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 10000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 10000)
                    {
                        myHero.gold -= 10000;
                        myHero.healthBonus = 400;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 10000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 10000)
                    {
                        myHero.gold -= 10000;
                        myHero.healBonus = 400;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 10000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void FortyFive(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 100 Armor -25000 gold
2. Sword - 500 Damage -25000 gold
3. Staff - 500 Magic -25000 gold
4. Amulet - 500 Health -25000 gold
5. Healing Tome - 500 Healing -25000 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 25000)
                    {
                        myHero.gold -= 25000;
                        myHero.armorBonus = 100;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 25000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 25000)
                    {
                        myHero.gold -= 25000;
                        myHero.attackBonus = 500;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 25000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 25000)
                    {
                        myHero.gold -= 25000;
                        myHero.magicBonus = 500;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 25000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 25000)
                    {
                        myHero.gold -= 25000;
                        myHero.healthBonus = 500;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 25000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 25000)
                    {
                        myHero.gold -= 25000;
                        myHero.healBonus = 500;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 25000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        private void Fifty(Hero myHero)
        {
            Console.WriteLine(@"
1. Armor - 1000 Armor -50000 gold
2. Sword - 3000 Damage -50000 gold
3. Staff - 3000 Magic -50000 gold
4. Amulet - 3000 Health -50000 gold
5. Healing Tome - 3000 Healing -50000 gold");
            DisplayStats(myHero);
            string answer = Console.ReadLine();
            Console.Clear();

            switch (answer)
            {
                case "1":
                    if (myHero.gold >= 50000)
                    {
                        myHero.gold -= 50000;
                        myHero.armorBonus = 1000;
                        myHero.armor += myHero.armorBonus;
                        Console.WriteLine("You bought armor for 50000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "2":
                    if (myHero.gold >= 50000)
                    {
                        myHero.gold -= 50000;
                        myHero.attackBonus = 3000;
                        myHero.maxAttack += myHero.attackBonus;
                        myHero.minAttack += myHero.attackBonus;
                        Console.WriteLine("You bought a sword for 50000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "3":
                    if (myHero.gold >= 50000)
                    {
                        myHero.gold -= 50000;
                        myHero.magicBonus = 3000;
                        myHero.maxMagic += myHero.magicBonus;
                        myHero.baseMinMagic += myHero.magicBonus;
                        Console.WriteLine("You bought a staff for 50000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "4":
                    if (myHero.gold >= 50000)
                    {
                        myHero.gold -= 50000;
                        myHero.healthBonus = 3000;
                        myHero.health += myHero.healthBonus; 
                        myHero.maxHealth += myHero.healthBonus;
                        Console.WriteLine("You bought an amulet for 50000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
                case "5":
                    if (myHero.gold >= 50000)
                    {
                        myHero.gold -= 50000;
                        myHero.healBonus = 3000;
                        myHero.maxHeal += myHero.healBonus;
                        myHero.minHeal += myHero.healBonus;
                        Console.WriteLine("You bought a healing tome for 50000 gold, you now have {0} gold left", myHero.gold);
                        //ClearScreen();
                    }
                    else
                    {
                        Console.WriteLine("You don not have enough money for this.");
                    }
                    break;
            }
        }

        public void DisplayStats(Hero myHero)
        {
            Console.WriteLine(@"
*************************************************************************
Name:           Level:          Health:           Attack Range:    
-------------------------------------------------------------------------
{0}             {1}             {2}               {3}-{4}
*************************************************************************
*************************************************************************
Magic Range:         Heal Range:          Armor:         Gold:      
-------------------------------------------------------------------------
{5}-{6}                  {7}-{8}              {9}             {10}
*************************************************************************
*************************************************************************
Magic Bonus:       Heal Bonus:          Armor Bonus:       Health Bonus:      
-------------------------------------------------------------------------
{11}                       {12}                  {13}             {14}
*************************************************************************
*************************************************************************
Attack Bonus:      Death Count:         Survival Count:
-------------------------------------------------------------------------
{15}                       {16}                   {17}
*************************************************************************", myHero.Identifier, myHero.level, myHero.health, myHero.minAttack, myHero.maxAttack, myHero.minMagic, myHero.maxMagic, myHero.minHeal, myHero.maxHeal, myHero.armor, myHero.gold, myHero.magicBonus, myHero.healBonus, myHero.armorBonus, myHero.healthBonus, myHero.attackBonus, myHero.deathCount, myHero.highestSurvival);
        }

        private void ClearScreen()
        {
            Console.ReadKey();
            Console.Clear();
        }
    }
}




If you need a more adequate explanation, let me know and I'll try to clarify tomorrow when I have some coffee ;)/>

Anyway, moving on. I want to create an inventory system where you can store items/loot you find. I think I should use Lists and I know how they work on a basic level. However I think I need to use list in a way that lets me store objects like:

//Just ideas in a somewhat pseudocode fashion
WeaponType = Sword;
WeaponName = "Sword of a Thousand Angry People's Unfortunate Past";
Weapon stats = 12 strength, 20 vitality, 3 magic find, 4 gold find;

Inventory.Add(AboveMentionedWeapon); //Assume inventory is a list that you can add objects too



After I get the inventory working, I want to be able to have an equipment page where the player can actually equip items and have their stats added to the character. And code that will let me move items between inventory and equipped and back. These are two issues that I haven't been able to get my head around and lead to the work around you saw in the first game's code. However, I do want this game to be better so I'm not going to settle for a work around this time.

You can go to asku.codeplex.com to download the client for my previous game and/or its source code to get a better understanding of how my work around works if you want to. Or you can ask for me to clarify more if I need to. Thanks in advance for the help!

Is This A Good Question/Topic? 0
  • +

Replies To: Inventory/Equipped Items Text Based RPG

#2 MATTtheSEAHAWK   User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Inventory/Equipped Items Text Based RPG

Posted 04 August 2013 - 08:06 PM

Alright, you're being kind of vague on what you need help for, but I'll do the best I can. If I were in your situation, I would make a class for your inventory, an inventory item, and you can make subclasses of inventory item for things like weapons, potions (whatever you'll have), armor, and whatever. You can then make functions in your inventory class based around these items. Maybe you can use a hotkey array and then you can do more in-depth management? I don't know.

If you're looking for someone to design and make your classes, you've come to the wrong forum. We can help you with problems in code, and come up with ideas, but you have to make an attempt first. We're not going to write a rough draft or anything like that for you.

One last thing, reading through your gargantuan 1000 line snippet, your code seems EXTREMELY repetitive. If you're just doing stats per level and traits, you should use a mathematical formula based on level to generate stats without being so repetitive.
Was This Post Helpful? 0
  • +
  • -

#3 Witchking   User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 189
  • Joined: 17-February 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 02:23 AM

I agree with MATTtheSEAHAWK, you'll need to be creating formulas for things like the player level, armor bonuses, weapon bonuses, xp gain etc, instead of hardcoding everything and ending up with a thousand lines of code like you do. You can get rid of the CalcHeroLevel class. Instead i suggest you give your Character class an Xp property, a Level property and an AddXp method that also calculates the character's level using your formula.

So your character class would have something like this
class Character
{
	private int _Xp;
	public int Xp
	{
		get
		{
			return _Xp;
		}
	}
	
	private int _Level;
	public int Level
	{
		get
		{
			return _Level;
		}
	}
	
	public void AddXp(int xp)
	{
		if (xp < 0) throw new ArgumentOutOfRangeException();
		_Xp += xp;
		
		_Level = //calculate the level 
	}
}
Of course you'll probably want to add more stuff to the class such as an Inventory property, using an Inventory collection class you would write.


What you're doing in your shop class is just horrible. Instead of all of those lines of hardcoding everything, you should create a Shop class with an instance of your Inventory class and methods for buying and selling. As for displaying things, you can give your Item class a LevelRequired property, and just show everything the hero has access to, like so
public Item[] GetAvailable()
{
	return this.Inventory.Where(n => Hero.Level >= n.LevelRequired).ToArray();
}

This post has been edited by Witchking: 05 August 2013 - 02:24 AM

Was This Post Helpful? 1
  • +
  • -

#4 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 05:15 AM

View PostMATTtheSEAHAWK, on 04 August 2013 - 08:06 PM, said:

Alright, you're being kind of vague on what you need help for, but I'll do the best I can. If I were in your situation, I would make a class for your inventory, an inventory item, and you can make subclasses of inventory item for things like weapons, potions (whatever you'll have), armor, and whatever. You can then make functions in your inventory class based around these items. Maybe you can use a hotkey array and then you can do more in-depth management? I don't know.

If you're looking for someone to design and make your classes, you've come to the wrong forum. We can help you with problems in code, and come up with ideas, but you have to make an attempt first. We're not going to write a rough draft or anything like that for you.

One last thing, reading through your gargantuan 1000 line snippet, your code seems EXTREMELY repetitive. If you're just doing stats per level and traits, you should use a mathematical formula based on level to generate stats without being so repetitive.


Which is why I said that I'd clarify if need be. I can make classes for items and all that, the problem is, adding the item to the inventory with its stats included. I think if I can wrap my head around my inventory problem, it shouldn't be too difficult to apply those same concepts to what's needed for the equipped item list.

I don't want anyone to write my code for me, I need help with the concepts and ideas. From there I can go and try to implement what I've learned. Hopefully it works, but if it doesn't I can then return with the broken code. If I just wanted someone to write the code for me, I'd go ahead and host the project on an open source site and list a developer opening. Problem with that is, I wouldn't really learn from that. The first game had its problems because of the mindset I had of "just getting it done," and I would come up with whatever work around necessary. That led to a lot of bad hard coding. This time I want to go through and do it right while learning. That means getting help with the concepts of making it more dynamic. I've already made some improvements on the previous game that I was able to figure out myself, but I'm somewhat stuck on this whole inventory thing.


View PostWitchking, on 05 August 2013 - 02:23 AM, said:

I agree with MATTtheSEAHAWK, you'll need to be creating formulas for things like the player level, armor bonuses, weapon bonuses, xp gain etc, instead of hardcoding everything and ending up with a thousand lines of code like you do. You can get rid of the CalcHeroLevel class. Instead i suggest you give your Character class an Xp property, a Level property and an AddXp method that also calculates the character's level using your formula.

So your character class would have something like this
class Character
{
	private int _Xp;
	public int Xp
	{
		get
		{
			return _Xp;
		}
	}
	
	private int _Level;
	public int Level
	{
		get
		{
			return _Level;
		}
	}
	
	public void AddXp(int xp)
	{
		if (xp < 0) throw new ArgumentOutOfRangeException();
		_Xp += xp;
		
		_Level = //calculate the level 
	}
}
Of course you'll probably want to add more stuff to the class such as an Inventory property, using an Inventory collection class you would write.


What you're doing in your shop class is just horrible. Instead of all of those lines of hardcoding everything, you should create a Shop class with an instance of your Inventory class and methods for buying and selling. As for displaying things, you can give your Item class a LevelRequired property, and just show everything the hero has access to, like so
public Item[] GetAvailable()
{
	return this.Inventory.Where(n => Hero.Level >= n.LevelRequired).ToArray();
}


Thanks. My biggest problem with the xp and level formula was that I wasn't able to come up with a formula that created an xp curve that I was happy with. I'm going to spend more time working on that this time, or if I simply can't find one, I'll scale the xp gained accordingly. Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#5 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 05:44 AM

I have an item base class and a weapon subclass that derives from the bass class (more sub classes will be added once I get this one working right).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace The_Darkest_Hour.Items_and_Inventory
{
    class Item
    {
        protected string name, weaponType;
        protected int damage, strength, agility, intelligence;
        protected double magicFind, goldFind;
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace The_Darkest_Hour.Items_and_Inventory
{
    class Weapon : Item
    {
        public Weapon()
        {
            //DoNothing because nothing was passed into the constructor
        }

        public Weapon(string name, string weaponType, int damage, int strength, int agility, int intelligence, double goldFind, double magicFind)
        {
            this.name = name;
            this.weaponType = weaponType;
            this.damage = damage;
            this.strength = strength;
            this.agility = agility;
            this.intelligence = intelligence;
            this.goldFind = goldFind;
            this.magicFind = magicFind;
        }
    }
}



So now I just need to take this information, and pass it to a list for an inventory. Or maybe its more complicated than that?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7456
  • View blog
  • Posts: 25,097
  • Joined: 05-May 12

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 05:52 AM

View Postvalondon, on 05 August 2013 - 08:15 AM, said:

Thanks. My biggest problem with the xp and level formula was that I wasn't able to come up with a formula that created an xp curve that I was happy with. I'm going to spend more time working on that this time, or if I simply can't find one, I'll scale the xp gained accordingly. Thanks for your help.

If you need a hand tweaked XP curve, there are several alternatives. I'll list 4 that come to my mind straight away:
- Have a hard coded array/list in your code with the key points.
- Have a disjoint function instead of a single continuous function to compute the curve.
- Load the curve points from a resource/file.
- Generate the hard coded array/list using T4.
Was This Post Helpful? 0
  • +
  • -

#7 Witchking   User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 189
  • Joined: 17-February 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 05:56 AM

First of all, you should use properties for anything that is not private.

Secondly, your Item class seems to have a lot of unneeded stuff, for example, if you create a Potion subclass, will that need the weaponType? Your Item base class should probably have things like an int property for its value, and maybe a boolean for whether it can be sold or gotten rid of, so the player doesn't accidentally sell a quest item. You also talked about the player not being able to buy things until they're a certain level, and if this applies to all types of items, you would want to add a property for the level required.

Also instead of using a string for the weapon type, i would use a very general enum. For example Melee, Magic or Ranged.
Was This Post Helpful? 1
  • +
  • -

#8 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 06:07 AM

View PostWitchking, on 05 August 2013 - 05:56 AM, said:

First of all, you should use properties for anything that is not private.

Secondly, your Item class seems to have a lot of unneeded stuff, for example, if you create a Potion subclass, will that need the weaponType? Your Item base class should probably have things like an int property for its value, and maybe a boolean for whether it can be sold or gotten rid of, so the player doesn't accidentally sell a quest item. You also talked about the player not being able to buy things until they're a certain level, and if this applies to all types of items, you would want to add a property for the level required.

Also instead of using a string for the weapon type, i would use a very general enum. For example Melee, Magic or Ranged.


So maybe instead have it just be itemType? Fair points, I'll make those changes. Though with the enums, I think it needs to be more than Melee, Magic, or Ranged. Something more along the lines of Axe, Sword, Staff, Bow, Wand, Crossbow. Variety is something I'm going for there.

View PostSkydiver, on 05 August 2013 - 05:52 AM, said:

If you need a hand tweaked XP curve, there are several alternatives. I'll list 4 that come to my mind straight away:
- Have a hard coded array/list in your code with the key points.
- Have a disjoint function instead of a single continuous function to compute the curve.
- Load the curve points from a resource/file.
- Generate the hard coded array/list using T4.


With the second one, would it look something like:
if (player.level <= 10)
     MethodForFirstCurve();
else if (player.level <= 40 && player.level > 10)
     MethodForSecondCurve();


Was This Post Helpful? 0
  • +
  • -

#9 Witchking   User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 189
  • Joined: 17-February 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 06:32 AM

View Postvalondon, on 05 August 2013 - 03:07 PM, said:

So maybe instead have it just be itemType? Fair points, I'll make those changes. Though with the enums, I think it needs to be more than Melee, Magic, or Ranged. Something more along the lines of Axe, Sword, Staff, Bow, Wand, Crossbow. Variety is something I'm going for there.


Well, you'll probably have a bunch of stats for each weapon such as damage, accuracy and so forth. Now maybe an axe has a higher damage but a lower accuracy compared to a sword, but if the two are not somehow fundamentally different, you could just give both of them the melee weapon type, while the difference is in their stats and name.
Was This Post Helpful? 1
  • +
  • -

#10 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 06:59 AM

Looking at your system, you have a player class with base stats and then bonuses that come from gear?

Don't confuse the profession with the player. Use some OOP ( Holy massive exposed variables, Batman! )

Start with the bonuses:
class StatBonus {
	public int Armor { get; set; }
	public int Health { get; set; }
	public int Heal { get; set; }
	public int Attack { get; set; }
	public int Magic { get; set; }
	public static StatBonus Empty = new StatBonus() { Armor = 0, Health = 0, Heal = 0, Attack = 0, Magic = 0 };
	public StatBonus Add(StatBonus that) {
		return new StatBonus() {
			Armor = this.Armor + that.Armor,
			Health = this.Health + that.Health,
			Heal = this.Heal + that.Heal,
			Attack = this.Attack + that.Attack,
			Magic = this.Magic + that.Magic
		};
	}
}



Note that we can add them up. This will be helpful with multiple pieces of kit.

This is enough to get us a functioning item class:
class Item {
	public enum SlotType { Hand, Body, None };
	public SlotType Slot { get; set; }
	public int Cost { get; set; }
	public string Name { get; set; }
	public StatBonus Bonuses { get; set; }
}




Aww, hell, let's flesh the rest out...

Because you do this a lot:
class StatRange {
	public readonly int minValue, maxValue;
	public StatRange(int minValue, int maxValue) {
		this.minValue = minValue;
		this.maxValue = maxValue;
	}
	public StatRange Add(int i) { return new StatRange(minValue + i, maxValue + i); }
}


The Add method here is also for ease of use.

Now, to hold your stats:
class Stats {
	public int Armor { get; set; }
	public int Health { get; set; }
	public StatRange Heal { get; set; }
	public StatRange Attack { get; set; }
	public StatRange Magic { get; set; }
	public Stats Add(StatBonus sb) {
		return new Stats() {
			Armor = this.Armor + sb.Armor,
			Health = this.Health + sb.Health,
			Heal = this.Heal.Add(sb.Heal),
			Attack = this.Attack.Add(sb.Attack),
			Magic = this.Magic.Add(sb.Magic),
		};
	}
	public static Stats Empty = new Stats() { Armor = 0, Health = 0, Heal = new StatRange(0, 0), Attack = new StatRange(0, 0), Magic = new StatRange(0, 0) };
}



Consider, we can now have multiple instances of StatBonus added in.

What is Character? I can't imagine. If you can have other things, like Thief, etc, then we might want to define it:
interface IRpgCharacter {
	int GetLevel(int xp);
	Stats GetLevelStats(int level);
	string Name { get; }
}



Now, some meat.
class Hero : IRpgCharacter {
	private Stats[] levels;
	public Hero() {
		this.levels = new Stats[] { 
		Stats.Empty,
		new Stats() { Armor=5, Health=20, Heal=new StatRange(1,7), Attack=new StatRange(1,11), Magic=new StatRange(1,11) },
		new Stats() { Armor=15, Health=25, Heal=new StatRange(5,16), Attack=new StatRange(5,16), Magic=new StatRange(5,16) },
	};
	}
	public int GetLevel(int xp) {
		if (xp < 20) {
			return 1;
		} else if (xp < 100) {
			return 2;
		} else {
			return 0;
		}
	}
	public Stats GetLevelStats(int level) { return (level > 0 && level < levels.Length) ? levels[level] : levels[0]; }
	public string Name { get { return "Hero"; } }
}



So, basically, the class holds level jumps and stats steps.

Now, our player:
class Player {
	private class ItemOn {
		public Item Item { get; set; }
		public bool Worn { get; set; }
	}
	private List<ItemOn> items;
	public Player(IRpgCharacter pc) {
		this.PlayerClass = pc;
		this.items = new List<ItemOn>();
	}
	public IRpgCharacter PlayerClass { get; private set; }
	public int Xp { get; set; }
	public int Level { get { return PlayerClass.GetLevel(Xp); } }
	public Stats BaseStats { get { return PlayerClass.GetLevelStats(Level); } }

	public StatBonus Bonuses {
		get {
			var tot = StatBonus.Empty;
			items.ForEach((i) => { if (i.Worn) { tot = tot.Add(i.Item.Bonuses); } });
			return tot;
		}
	}
	public Stats CurrentStats { get { return BaseStats.Add(Bonuses); } }

	public int Gold { get; set; }
}



Our player holds xp, gold, and items. Importantly, what items are currently worn. This lets all the bonuses to be added up and sanely maintained.

For a shop:
class Shop {
	public List<Item> GetItems(int level) {
		var items = new List<Item>();
		if (level < 5) {
			items.Add(new Item() { Name = "Armor", Bonuses = new StatBonus() { Armor = 2 }, Cost = 10, Slot = Item.SlotType.Body });
			items.Add(new Item() { Name = "Sword", Bonuses = new StatBonus() { Attack = 5 }, Cost = 10, Slot = Item.SlotType.Hand });
			items.Add(new Item() { Name = "Staff", Bonuses = new StatBonus() { Magic = 5 }, Cost = 10, Slot = Item.SlotType.Hand });
			items.Add(new Item() { Name = "Amulet", Bonuses = new StatBonus() { Health = 5 }, Cost = 10, Slot = Item.SlotType.Hand });
			items.Add(new Item() { Name = "Healing Tome", Bonuses = new StatBonus() { Health = 5 }, Cost = 10, Slot = Item.SlotType.None });
		}
		return items;
	}

	public void ShowStore(Player player) {
		var items = GetItems(player.Level);



You could actually store that in a static array. I'll leave the show to you.

Well, I had fun. Hope this helps.
Was This Post Helpful? 3
  • +
  • -

#11 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 11:54 AM

Thank you to baavgai, that code good and helpful. Unfortunately it mostly applies to make my old game's code more robust as opposed to helping me with my problem here, though I can see a few uses for it (particularly the shop one - that can be altered to fit some changing needs) and ways to more dynamically handle changing stats). So thank you =)

Now, I've spent some time on my inventory issue here, and this is what I've got:

/*
This is the same code that was seen earlier. I kept it as is to quickly get a working example out of it. 
*/
class Weapon : Item 
    {
        public Weapon()
        {
            //DoNothing because nothing was passed into the constructor
        }

        public Weapon(string name, string weaponType, int damage, int strength, int agility, int intelligence, double goldFind, double magicFind)
        {
            this.name = name;
            this.weaponType = weaponType;
            this.damage = damage;
            this.strength = strength;
            this.agility = agility;
            this.intelligence = intelligence;
            this.goldFind = goldFind;
            this.magicFind = magicFind;
        }
    }
}



class Player : Character
    {
        //quite a few of these are irrelevant to this discussion, I have the relevant one marked with a comment
        int mainStat;
        int critChance;
        int critDamage;
        float magicFind;
        float goldFind;
        string Rogue = "Rogue";
        string Hunter = "Hunter";
        string Warrior = "Warrior";
        string Guardian = "Guardian";
        string Mage = "Mage";
        string Cleric = "Cleric";
        string profession = null;
        string mainStatName;
        bool isHardCore = false;
        bool isAlive = true;
        public List<object> Inventory = new List<object>(); //THIS IS THE RELEVANT PART



class MainGame
    {
        Player myHero;
        Mob mob;

        public MainGame()
        {
            myHero = new Player();
            mob = new Mob();

            myHero.Initialize(myHero);

            Console.WriteLine(myHero.Identifier);
            myHero.DisplayProfession(myHero);

            //relevant code to inventory problem here
            Console.WriteLine("\n\nYou come across a sword and a bow. You pick them up and add them to your inventory.");
            Weapon aSword = new Weapon("Sword of Rightouseness", "Sword", 4, 4, 0, 0, 0, 0);
            Weapon aBow = new Weapon("Bow of True Aim", "Bow", 10, 0, 6, 0, 0, 0);
            myHero.Inventory.Add(aSword);
            myHero.Inventory.Add(aBow);

            int i = 1;
            foreach (object displayInventory in myHero.Inventory)
            {
                Console.WriteLine(i + ". " + displayInventory);
                i++;
            }

            Console.WriteLine("\n\nPress any key to end the program...");
            Console.ReadKey();
            //do
            //{
            //}while();
        }



Now my problem here is that when I try to print what's in the inventory, I get this:
Posted Image

This obviously isn't what I wanted displayed. At the very least I want the name of the item displayed, but the name and type would be nice too. If I have to, I would settle for having everything displayed, but there should be a way to keep the integers from being displayed. Now if the user selects an item to view, there should be a way for them to see:
Item Name - "Bow of Righteousness"
Item Type - "Bow"
Damage - 10
Agility - 6

I've included the visual studio project for the game and all of the code if anyone wants to play around with it if I accidentally left something out. But I believe that covers it all.
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15800
  • View blog
  • Posts: 63,300
  • Joined: 12-June 08

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 12:04 PM

Why are you using 'object'? Why not a specific type? Does that specific type have a "print" function that returns the relevant content of the object in a format that is pleasing?
23	            int i = 1;
24	            foreach (object displayInventory in myHero.Inventory)
25	            {
26	                Console.WriteLine(i + ". " + displayInventory);
27	                i++;
28	            }





... so why isn't this a specific object type?
19	        public List<object> Inventory = new List<object>(); //THIS IS THE RELEVANT PART

Was This Post Helpful? 0
  • +
  • -

#13 valondon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 04-August 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 12:07 PM

View Postmodi123_1, on 05 August 2013 - 12:04 PM, said:

Why are you using 'object'? Why not a specific type? Does that specific type have a "print" function that returns the relevant content of the object in a format that is pleasing?
23	            int i = 1;
24	            foreach (object displayInventory in myHero.Inventory)
25	            {
26	                Console.WriteLine(i + ". " + displayInventory);
27	                i++;
28	            }





... so why isn't this a specific object type?
19	        public List<object> Inventory = new List<object>(); //THIS IS THE RELEVANT PART


Because I am storing objects in the list (the items which are objects)
Was This Post Helpful? 0
  • +
  • -

#14 Witchking   User is offline

  • D.I.C Head

Reputation: 68
  • View blog
  • Posts: 189
  • Joined: 17-February 13

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 12:09 PM

Likely OP doesn't have a very good understanding of polymorphism. I did this too starting out.

EDIT:


View Postvalondon, on 05 August 2013 - 09:07 PM, said:

Because I am storing objects in the list (the items which are objects)

All types in .NET are objects at their most basic. This means you could add anything from an int to a FileStream in your list. What you should do is use a List<Item>. Your Weapon class inherits your Item class, so an instance of Weapon is also a type of Item.

This post has been edited by Witchking: 05 August 2013 - 12:14 PM

Was This Post Helpful? 0
  • +
  • -

#15 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15800
  • View blog
  • Posts: 63,300
  • Joined: 12-June 08

Re: Inventory/Equipped Items Text Based RPG

Posted 05 August 2013 - 12:12 PM

Quote

Because I am storing objects in the list (the items which are objects)


No.. I would wager you are storing things of type "Item" in the inventory.

@Witchking - yeah I am guessing that as well.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3