Click here to Skip to main content
15,746,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I'm currently doing a school project where our task is to create a game.
My game is match but the number on the card represent the amount of points you earn (e.g if you get two '7's' you would earn 7 point.)

The images are currently randomized in a picture box. If there is a way you know of which can make it work please let me know... as I'm currently stuck on this problem. (also could you make you explanation easy to understand because I'm not good at coding.)

(also using Microsoft Visual Studios 2015)

What I have tried:

    FlippedImage1 = null;
    FlippedImage2 = null;
    pic2.Enabled = false;
    pic1.Enabled = false;
    ScoreCounter.Text = Convert.ToString(Convert.ToInt32(ScoreCounter.Text) + 10);
    ScoreCounter.Text = Convert.ToString(Convert.ToInt32(ScoreCounter.Text) +0); //This is my current code
Updated 16-Jun-19 21:47pm

1 solution

Try not to write too much on one line. So instead of
ScoreCounter.Text = Convert.ToString(Convert.ToInt32(ScoreCounter.Text) + 10);

try something like:
int currentScore = Convert.ToInt32(ScoreCounter.Text);
int newScore = currentScore + 10;
string newScoreText = Convert.ToString(newScore);
ScoreCounter.Text = newScoreText;

Set a break point (F9) at the start of the calculation, hit F5 to start debugging then single step (F10/F11) line by line once your breakpoint hit. Check the values are as you expect for each line.

Once you have a specific line not having the affect you expect, then you can google that - and if still having questions ask here.

It is much easier to get help if you can say "I have line X, I expect it to do Y, but I observe Z". As it is now, we can't see what you expect the code to be doing, and that makes it hard to help you.

PS: Great you name your text box ScoreCounter - it is nice not seeing TextBox1 as we normally see from beginners!
Share this answer
Member 14502643 17-Jun-19 3:54am    
Hi thanks for responding..
Sorry for adding so much code as i am unsure on the amount of information which is required, so thank you.

I'm still slightly confuse how to included the amount of points which you earn though

But thank you.
lmoelleb 17-Jun-19 6:58am    
One of your lines appears to add 10. The other one does nothing. As we do not know where you store the number on the card, we can't tell you how to read it. Typically you would have the current card stored in a variable somewhere, in that case you can just add currentCard.Points or similar - but then you of course need to set currentCard when it becomes current. :)
Member 14502643 18-Jun-19 4:58am    
thanks for responding... had to hand up my assignment where i just didnt understand how to add it. But thank you sooooooooo much for trying to help. I decided to cut it out because i just gave up.

Thank you once again
[no name] 18-Jun-19 5:33am    
yeah, this is exactly what I need
BillWoodruff 18-Jun-19 15:29pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900