Jump to content


C# Item Equipping


8 replies to this topic

#1 N0MAD

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 04 March 2010 - 03:57 AM

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.

#2 SamuraiCrow

    Senior Member

  • Members
  • PipPipPipPip
  • 459 posts

Posted 05 March 2010 - 02:41 AM

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

#3 N0MAD

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 05 March 2010 - 02:57 AM

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.

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 05 March 2010 - 06:19 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 N0MAD

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 05 March 2010 - 01:20 PM

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

#6 imerso

    Senior Member

  • Members
  • PipPipPipPip
  • 431 posts
  • LocationBrasil

Posted 05 March 2010 - 10:44 PM

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.

#7 N0MAD

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 05 March 2010 - 11:28 PM

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.

#8 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 05 March 2010 - 11:55 PM

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. :)
reedbeta.com - developer blog, OpenGL demos, and other projects

#9 N0MAD

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 06 March 2010 - 04:42 AM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users