Simple Game, Unable to Grasp Certain Concepts

mflij511

New member
Joined
Jul 1, 2010
Messages
1
Programming Experience
Beginner
Ok, I've researched for hours about classes, creating classes, creating obj's of that class, but every tutorial I've seen has either talking about things that are different from what I'm doing, or they were written with the assumption that I understand X or Y. What I want seems simple enough but it's just not clicking. Here's what I'm trying to accomplish:

1. Player chooses from a list of characters
2. That character has specific attributes (power level, experience points, ect..)
3. When entering the combat page, the specific attributes are displayed in text boxes
with respective labels.
4. When battle is over, experience points are handed out and saved in player class.

It's probably laughable to some how simple this is but I'm really struggling with it. Thanks in advance!
 
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objCharacter As Character

objCharacter = New Character("Jhon", 100, 10, 50)
lstCharacters.Items.Add(objCharacter)

objCharacter = New Character("Me", 100, 100, 100)
lstCharacters.Items.Add(objCharacter)

End Sub

Private Sub btnEnterBattle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnterBattle.Click
'you can selected the character from list and press this button and you would be return the object from the list

Dim objCharacter As Character
'you wont need to do type cast if you have option strict turned off.
objCharacter = CType(lstCharacters.SelectedItem, Character)

'Now you can access all the attributes of character like objCharater.Name and you ill get the Name of selected character.


End Sub
End Class


Public Class Character
Public Name As String
Public Power As Integer
Public Experience As Integer
Public Points As Double

'Constructor
Public Sub New(ByVal chName As String, ByVal chPower As Integer, ByVal chExperience As Integer, ByVal chPoints As Double)

Name = chName
Power = chPower
Experience = chExperience
Points = chPoints

End Sub

'Override the ToString function other wise it would return the Class Name.
Public Overrides Function ToString() As String
Return Name.ToString()
End Function
End Class

I hope it is what you where expecting for.
 
Back
Top