PDA

Click to See Complete Forum and Search --> : Implememnting a Scoring System..Help


Obie
Aug 30th, 2000, 12:41 AM
I need to implement a scoring system on a game I have to make for my VB subject.

Basically player starts with 100pts.

Everytime they win ie 'win'light up in a given label, the player gains 10 points.

Everytime they lose ie 'lose'lights up in a given lable, the player is deducted 10 points.

Now how the hech would I do this?

Any Ideas?

Mad Compie
Aug 30th, 2000, 01:02 PM
This is just a silly If...Then...Else... case

V(ery) Basic
Aug 30th, 2000, 01:04 PM
you might want to use a class module for this. Just call it 'cScore' . Then write this:


'cScore
Private m_Score As Integer

Private Sub Class_Initialise()
m_Score = 100
End Sub

Sub AddPoints(Points As Integer)
'You could put some routine here to check that 'Points' is
'in a certian range or something
m_Score = m_Score + Points
End Sub

Function GetPoints() As Integer
GetPoints = m_Score
End Function

Sub SetPoints(Points As Integer) As Integer
m_Score = Points
End Sub

'Form
Dim Score As cScore

Private Sub Form_Load()
Set Score = New cScore
'You stuff
End Sub

'Put this in the code block which lights up the 'win' label:
'...
Score.AddPoints(10)
'...

'Put this in the code block which lights up the 'lose' label:
'...
Score.AddPoints(-10)

'To get the player's score, use this:
Score.GetPoints


I hope you find this useful. Using a class module is safer than using a global variable, because the global variable can be modified from anywhere in the application. Also, you can easily have scores for two players, like this:


'(The cScore class stays exactly the same)

'Form
Dim Plyr1Score As cScore
Dim Plyr2Score As cScore

Private Sub Form_Load()
Set Plyr1Score = New cScore
Set Plyr2Score = New cScore
'You stuff
End Sub

'Add 10 points to Player1 and take 20 from Player2:
'...
Plyr1Score.AddPoints(10)
Plyr2Score.AddPoints(10)
'...

'Set Player2's score to Player1's score:
Plyr2.SetPoints(Plyr1Score.GetPoints)


Also remember that to save memory add this:

Private Sub Form_Unload()
Set Plyr1Score = Nothing
Set Plyr2Score = Nothing
End Sub


I hope this is what you want,

Me