C# Item Equipping
Posted 04 March 2010 - 03:57 AM
I am using Visual Studio C# to make an RPG, right now so far i have the program give you items when you "open a treasure chest" and these items are put into an array. After these items are put into an array and you open your inventory form the items stored in the array are put into labels (Short sword = array and that is in slot 1; so on and so forth). I now want to know how to, when slot1 is clicked on (it is a label with "Short Sword" written in it due to an array loading it) i want it to be equiped to a certain place, like to the left hand for example.
If this isn't too confusing and someone could give me some guidance on a way to do this that would be great.
Posted 05 March 2010 - 02:41 AM
When doing weapons classes you want them to typically be that: classes. You want a weapon class that is abstract that describes what types of information about the weapon are known. Then you can make more specific classifications such as a one-handed weapon. If it is a one-handed weapon you can have an "equip" method that will check if it is being equipped in the proper location on the character.
I hope this helps,
Posted 05 March 2010 - 02:57 AM
Many items after i have the base game coded.. just keep expanding.
Posted 05 March 2010 - 06:19 AM
You should probably have a class hierarchy for items, like maybe a CItem class and a CWeapon class that derives from CItem; then maybe CMeleeWeapon and CRangedWeapon would be subclasses of CWeapon. These classes would have various methods allowing them to be picked up, dropped, etc. and properties indicating weight, damage, etc.
Then you could have a CCharacter class, and as a field in that, have an array of (references to) CItems representing the character's inventory. You could also have a field holding a reference to the currently wielded weapon on the left hand, and another for the right hand. A method on CCharacter would exist to equip a CWeapon from the inventory, which would check which hand(s) it is for and set the references appropriately.
Posted 05 March 2010 - 01:20 PM
Posted 05 March 2010 - 10:44 PM
After you make some simple games, you get enough knowledge to at least understand what people are saying above.
Posted 05 March 2010 - 11:28 PM
Posted 05 March 2010 - 11:55 PM
Posted 06 March 2010 - 04:42 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users