Results 1 to 3 of 3

Thread: Implememnting a Scoring System..Help

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    13

    Unhappy

    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?

  2. #2
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Thumbs down

    This is just a silly If...Then...Else... case

  3. #3
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    you might want to use a class module for this. Just call it 'cScore' . Then write this:

    Code:
    '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:

    Code:
    '(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:
    Code:
    Private Sub Form_Unload()
    Set Plyr1Score = Nothing
    Set Plyr2Score = Nothing
    End Sub
    I hope this is what you want,

    Me
    Courgettes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width