Declaring Custom Variables/Properties
-
Hiya all. I'm planning on making a program for a card game I have (Munchkin, if you wanna know). In creating this program, I was hoping to declare a Player type variable, if it's possible, and create my own properties like Level, Gender, and so on. Unfortunately, I have been unable to find a way to do this. If anyone can help me, or can think of another way to accomplish my goal (XML files might work, I dunno), I'd appreciate it. Thanks in advance. EDIT: In case my post wasn't clear enough, I want something like this:
Dim plrMike as Player ... plrMike.Level = 1 plrMike.Gender = Male
Signed, Mecha-Poobah of The Love Which Dare Not Speaketh Its Name, Codemonkey Jackson Title Generator - http://title.flywheel.org/ -
Hiya all. I'm planning on making a program for a card game I have (Munchkin, if you wanna know). In creating this program, I was hoping to declare a Player type variable, if it's possible, and create my own properties like Level, Gender, and so on. Unfortunately, I have been unable to find a way to do this. If anyone can help me, or can think of another way to accomplish my goal (XML files might work, I dunno), I'd appreciate it. Thanks in advance. EDIT: In case my post wasn't clear enough, I want something like this:
Dim plrMike as Player ... plrMike.Level = 1 plrMike.Gender = Male
Signed, Mecha-Poobah of The Love Which Dare Not Speaketh Its Name, Codemonkey Jackson Title Generator - http://title.flywheel.org/One of two things you could do: 1) Create a Class: Assuming VB.NET: You will create a new class library named Player.vb. Assuming VB6: You will create a new class library named Player.cls. 2) Create a type/structure: Assuming VB.NET: Create a structure definition using Structure...End Structure. Assuming VB6: Create a type using Type ... End Type What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
One of two things you could do: 1) Create a Class: Assuming VB.NET: You will create a new class library named Player.vb. Assuming VB6: You will create a new class library named Player.cls. 2) Create a type/structure: Assuming VB.NET: Create a structure definition using Structure...End Structure. Assuming VB6: Create a type using Type ... End Type What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
Well, I went ahead and made a new class library (my new variable type ends up being Munchkin.Player.Character). I can do things now like assign "Male" to Character.Gender, but I can also do wacky things like Character.Gender = "Chicken". Another thing is that the maximum level is supposed to be ten, but I could make Character.Level whatever integer I want, even negatives. What do I do to limit what kinds of genders there are, or specify which ones do and don't work? As I sit here, I contemplate the last words of Socrates: "I drank what?".
-
Well, I went ahead and made a new class library (my new variable type ends up being Munchkin.Player.Character). I can do things now like assign "Male" to Character.Gender, but I can also do wacky things like Character.Gender = "Chicken". Another thing is that the maximum level is supposed to be ten, but I could make Character.Level whatever integer I want, even negatives. What do I do to limit what kinds of genders there are, or specify which ones do and don't work? As I sit here, I contemplate the last words of Socrates: "I drank what?".
Well, you could do a couple of things. You could have an Enum in your project, like:
Namespace Munchkin
Public Enum Genders
Male
Female
End Enum
End NamespaceThen, you could declare your Gender field like:
Public Gender As Genders
And the only valid thing to put in it would be:
someCharacter.Gender = Genders.Male
You could do the same thing with levels, or you could throw an exception if a character's level is set below 1 or above 10:
Public Class Character Private \_level As Integer Public Property Level() As Integer Get Return \_level End Get Set(ByVal Value As Integer) If Value < 1 Or Value > 10 Then Throw New ApplicationException("Level must be between 1 and 10") Else \_level = Value End If End Set End Property End Class
But guess what? Your Character is starting to sound more like a class than a structure... What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
Well, you could do a couple of things. You could have an Enum in your project, like:
Namespace Munchkin
Public Enum Genders
Male
Female
End Enum
End NamespaceThen, you could declare your Gender field like:
Public Gender As Genders
And the only valid thing to put in it would be:
someCharacter.Gender = Genders.Male
You could do the same thing with levels, or you could throw an exception if a character's level is set below 1 or above 10:
Public Class Character Private \_level As Integer Public Property Level() As Integer Get Return \_level End Get Set(ByVal Value As Integer) If Value < 1 Or Value > 10 Then Throw New ApplicationException("Level must be between 1 and 10") Else \_level = Value End If End Set End Property End Class
But guess what? Your Character is starting to sound more like a class than a structure... What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
>But guess what? Your Character is starting to sound more like a class than a structure... In that case, I must have misinterpreted your orginal advice; I had a project named Munchkin, a Class named Player, and a Structure named Character. It looked something like this:
Structure Character Public Name As String Public Gender As String Public Level As Integer End Structure
But I guess I should do the Class thing and the Structure thing seperately. Anyway, thanks for the help. I'm gonna try the Enum and Exception code now. As I sit here, I contemplate the last words of Socrates: "I drank what?". -
>But guess what? Your Character is starting to sound more like a class than a structure... In that case, I must have misinterpreted your orginal advice; I had a project named Munchkin, a Class named Player, and a Structure named Character. It looked something like this:
Structure Character Public Name As String Public Gender As String Public Level As Integer End Structure
But I guess I should do the Class thing and the Structure thing seperately. Anyway, thanks for the help. I'm gonna try the Enum and Exception code now. As I sit here, I contemplate the last words of Socrates: "I drank what?".Although, on the other hand, you could produce a Class that acts like a Character factory. Anyway, glad I could lend a hand. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.