9 Replies - 1786 Views - Last Post: 04 April 2012 - 09:42 AM Rate Topic: -----

#1 iaman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 30-March 12

Simple Scoring system for game

Posted 30 March 2012 - 03:46 PM

Im creating a game which has a simple score system which i dont understand why it isnt working the way i want it to
When loading the game the User starts with 10 credits and for every time they run the game it costs 2 credits
This is my code for this below

  Dim intCredits As Integer = 10
        Dim intGamesPlayed As Integer = 0
        intGamesPlayed += 1
        intCredits = intCredits - 2



it has no errors but it doesn't take away the credits each time the game is played besides the first time
so when i run the game it will go to 8 credits, and it will stay on 8 credits even if i run the game again
can anyone see a problem with my code above?
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Simple Scoring system for game

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Simple Scoring system for game

Posted 30 March 2012 - 03:50 PM

There is nothing wrong with the code, just wrong with the logic. If this code is run only in form load then it will only ever subtract 2 credits from the 10 credits. May I suggest using a CommandButton or something along those lines and use a code structure similar to this:
Public Class game
Dim intCredits As Integer = 10
Dim intGamesPlayed As Integer = 0

So that code would go in the declarations code section. Then for a click event of your button use this code:
intGamesPlayed += 1
intCredits -= 2

Cheers :)
Was This Post Helpful? 0
  • +
  • -

#3 iaman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 30-March 12

Re: Simple Scoring system for game

Posted 30 March 2012 - 03:58 PM

View PostDimitriV, on 30 March 2012 - 03:50 PM, said:

There is nothing wrong with the code, just wrong with the logic. If this code is run only in form load then it will only ever subtract 2 credits from the 10 credits. May I suggest using a CommandButton or something along those lines and use a code structure similar to this:
Public Class game
Dim intCredits As Integer = 10
Dim intGamesPlayed As Integer = 0

So that code would go in the declarations code section. Then for a click event of your button use this code:
intGamesPlayed += 1
intCredits -= 2

Cheers :)


Im not totally sure what you mean, Should have stated but this code isn't placed the form load I have it under a button, So that when the button is clicked this code should execute but it only does it once
Am i making sense or am i wrong? lol
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Simple Scoring system for game

Posted 30 March 2012 - 04:05 PM

In that case, every time you click the button it redeclares a credits variable holding 10 credits!
Was This Post Helpful? 0
  • +
  • -

#5 iaman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 30-March 12

Re: Simple Scoring system for game

Posted 30 March 2012 - 04:22 PM

View PostDimitriV, on 30 March 2012 - 04:05 PM, said:

In that case, every time you click the button it redeclares a credits variable holding 10 credits!


I read your first post again I see what you meant now, its working now :D you win again
ive another question related to my point system if you can help, ill try explaining this first
ive got 3 picture boxes with the images being random, if 2 of these images end up the same my game will add 5 credits, if 3 of the images end up the same my game will add 10 credits.

ive done If Statements for this, but ive ended up with alot of code for this as there is alot of combinations that can be right

 If img1 = 0 And img2 = 0 Then
            intCredits = intCredits + 5
        ElseIf img1 = 1 And img2 = 1 And img3 Then
            intCredits = intCredits + 10

And so on...
What method would you use to do this? any way of having less code?
Was This Post Helpful? 0
  • +
  • -

#6 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Simple Scoring system for game

Posted 30 March 2012 - 04:32 PM

Sorry, I can't think of one at the moment :)
Sorry...
Was This Post Helpful? 0
  • +
  • -

#7 iaman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 30-March 12

Re: Simple Scoring system for game

Posted 30 March 2012 - 04:34 PM

View PostDimitriV, on 30 March 2012 - 04:32 PM, said:

Sorry, I can't think of one at the moment :)
Sorry...


ok no problem the code works anyway so will do just was hoping it could be shorter
Thanks for all your help
Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 301
  • View blog
  • Posts: 1,782
  • Joined: 26-March 09

Re: Simple Scoring system for game

Posted 31 March 2012 - 01:52 AM

You could shorten it a little using the code below (should work???):

If img1 And img2 = 0 Then
        ' do something
    ElseIf img1 And img2 And img3 = 1 Then
        ' Do something else
    End If

This post has been edited by maj3091: 31 March 2012 - 01:59 AM

Was This Post Helpful? 0
  • +
  • -

#9 iaman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 30-March 12

Re: Simple Scoring system for game

Posted 31 March 2012 - 05:38 AM

View Postmaj3091, on 31 March 2012 - 01:52 AM, said:

You could shorten it a little using the code below (should work???):

If img1 And img2 = 0 Then
        ' do something
    ElseIf img1 And img2 And img3 = 1 Then
        ' Do something else
    End If


ye that should shorten it slightly thanks
Was This Post Helpful? 0
  • +
  • -

#10 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: Simple Scoring system for game

Posted 04 April 2012 - 09:42 AM

Although img1 And img2 And img3 = 1 is the same condition as img1 = 1 And img2 = 1 And img3 = 1, it is not the case that img1 = 0 And img2 = 0 is the same condition as img1 And img2 = 0.

Why? :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1