Click here to Skip to main content
15,886,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I create an inventory system like in an RPG game, where, as you get items, they'll be collected in a grouping control? I want to be able to distinguish certain items as weapons or armor, and be able to equip up to 2 of each. These items will add to the player's attack and defense. How can I do this?
Posted

1 solution

create an items class, having the contstructor include, type, damage, etc.. all your properties.
then you can populate an 'ArrayList' with different instances of the class.
i.e.:

Public Class Item

    Private itemName As String
    Private Const itemStrength as int = 100
    
    Property Line() As String
        Get
           Return itemName
        End Get
        Set(ByVal Value As String)
            mstrLine = Value
        End Set
    End Property
     
    ReadOnly Property strength() As Integer
       Get
           Return itemStrength
       End Get
    End Property
End Class


then populating the arraylist would be like:
inherits System.Collections;

...


 dim ar as new Arraylist()
 dim Itm as new Item()
 itm.Type = "Armor"
 itm.Damage = itm.itemStrength
 ar.Add(itm);


and so on so then you'l have an arraylist which will hold all your items. google Arraylist for more
 
Share this answer
 
v2
Comments
drummerboy0511 8-Oct-10 10:12am    
What is the "mstrLine = Value" line in the first block of code? It's causing an error on my machine... what is it supposed to do?
[no name] 15-Oct-10 10:02am    
parameter passd to the set sry my bad

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900