c# - Adding 0.5 to counter in result of a draw? -
i'm making game , need change code below in order add 0.5 running "playerscore++;" , "computerscore++;" respectively, when result happens come out in draw. instead of rolling again, demonstrated below, continue play. can't figure out! be:
playerscore += 0.5; computerscore += 0.5;
instead of message box popping up?
i hope makes sense, sorry! thanks!
private void button5_click_1(object sender, eventargs e) { playerdice = new dice(); int playerdiceno = playerdice.faceofdie; messagebox.show("your roll: " + playerdiceno); compdice = new dice(); int compdiceno = compdice.faceofdie; messagebox.show("computers roll: " + compdiceno); if (compdiceno == playerdiceno) { messagebox.show("draw - click roll or chance"); button5.enabled = true; button1.enabled = true; } }
you correct, addition assignment operator (+=
) give desired effect. try this:
if (compdiceno == playerdiceno) { computerscore += 0.5; playerscore += 0.5; button5.enabled = true; button1.enabled = true; }
it's shorthand doing:
computerscore = computerscore + 0.5; playerscore = playerscore + 0.5;
Comments
Post a Comment