Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 7-Oct-10 10:43am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
drummerboy0511 at 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?
JFergulbops at 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)

  Print Answers RSS
0 OriginalGriff 210
1 Richard MacCutchan 100
2 kbrandwijk 90
3 ProgramFOX 80
4 Sandeep Singh Shekhawat 70
0 Sergey Alexandrovich Kryukov 9,050
1 OriginalGriff 8,151
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 8 Oct 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100