c# - How to calculate a score when you drag and drop information from a textbox into multiple DrapDrop event -
i creating simple game application in windows forms. can drag information textbox , drop dragdrop event 1 mdi application another. ok problem having have multiple dragdrop events , trying calculate score of them.
what have tried far this.
public void score(int calcscore) { lblscore.text += calcscore.tostring(); } private void square_dragdrop(object sender, drageventargs e) { if(shape.contains("square")) { int calcscore = 0; calcscore++; score(calcscore); } } private void circle_dragdrop(object sender, drageventargs e) { if(shape.contains("circle")) { int calcscore = 0; calcscore++; score(calcscore); } }
the problem add score string result 11 instead of 2.
if try this:
public void score(int calcscore) { int totalscore =0; totalscore = totalscore + calcscore; lblscore.text += totalscore.tostring(); }
the problem once initialize totalscore sets total score 0 totalscore 1.
how can score calculated this?
1.
public void score(int calcscore) { lblscore.text += calcscore.tostring(); }
this cocatenation of strings. so:
"1" + "1" = "11";
just
"cat"+"cat" = "catcat";
2.
initialise
int totalscore =0; int calcscore =0;
at class level. every time use dragdrop or method score(int calcscore)
resetting these values zero.
Comments
Post a Comment