C# Item Equipping

64b0c0227ec0ba11b4e236a356e0caaf
0
N0MAD 101 Mar 04, 2010 at 03:57

I hope I’m putting this into the right place, but I was wondering if someone could help me out with a game I’m making.

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[0] 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.

8 Replies

Please log in or register to post a reply.

B7dcbc0c0f07253f25ff5c25fe38c081
0
SamuraiCrow 101 Mar 05, 2010 at 02:41

Hello N0MAD,

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,

–Sam

64b0c0227ec0ba11b4e236a356e0caaf
0
N0MAD 101 Mar 05, 2010 at 02:57

What i thought of after i made this post and was wondering if it would work was using databases (through microsoft office access) that had all the information like that, or would classes still be better than using databases. I would love to EVENTUALLY have maaaany items (weapons, armors, potions, etc.) that could be used but i will still look into classes.

Many items after i have the base game coded.. just keep expanding.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 05, 2010 at 06:19

Databases are huge overkill for a game that’s not an MMO.

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.

64b0c0227ec0ba11b4e236a356e0caaf
0
N0MAD 101 Mar 05, 2010 at 13:20

Mmmmmmmkay… i didn’t understand most of that but i will get my computer science teacher to help me out with that. Thanks Reed.

17ba6d8b7ba3b6d82970a7bbba71a6de
0
vrnunes 102 Mar 05, 2010 at 22:44

Not to bash you but… that is why people always suggest beginners to start with simpler games (tic-tac-toe, tetris, etc).

After you make some simple games, you get enough knowledge to at least understand what people are saying above.

64b0c0227ec0ba11b4e236a356e0caaf
0
N0MAD 101 Mar 05, 2010 at 23:28

I’ve made tic-tac-toe, pong, a small scale RPG, asteroid dodge, copter, and games of the such but, in my class we did not have the time to go over classes.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 05, 2010 at 23:55

Heh. That’s fine, but you really need to slow down and take a few more basic CS courses before you think seriously about doing a large project. Learning the tools of the trade actually is important. Right now it’s kind of like you’re trying to build a car with just a wrench and a screwdriver, if you see what I mean. :)

64b0c0227ec0ba11b4e236a356e0caaf
0
N0MAD 101 Mar 06, 2010 at 04:42

Oh i see exactly what you mean, but i am a very ambitious(if thats the right word) young man and I do rather enjoy just jumping into the larger things then taking it slow.