int - C#: How to make an integer rise its value on button click? -
i doing simple clicker game, know stupid ask ,but still learning ,so question how make "cost2" integer rise value +10 every button2 click.
here code:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace diamond_clicker { public partial class form1 : form { private int clicks = 0; private int counter = 1; const double factor = 0.95; double interval = 1000; int cost = 50; int cost2 = 500; public form1() { initializecomponent(); } private void form1_load(object sender, eventargs e) { } private void updatebutton() { if (clicks >= cost) button1.enabled = true; else button1.enabled = false; } private void updatebutton2() { if (clicks >= cost2) button2.enabled = true; else button2.enabled = false; } private void mydiamond_mouseup(object sender, mouseeventargs e) { mydiamond.image = image.fromfile("c:\\matej dodevski\\semos\\c#\\diamond clicker\\diamond.png"); } private void mydiamond_mousedown(object sender, mouseeventargs e) { mydiamond.image = image.fromfile("c:\\matej dodevski\\semos\\c#\\diamond clicker\\diamondmouseup.png"); clicks++; diamondsscore.text = "diamonds: " + clicks.tostring(); updatebutton(); updatebutton2(); } private void timer1_tick_1(object sender, eventargs e) { counter++; clicks = clicks + 1; diamondsscore.text = "diamonds: " + clicks.tostring(); updatebutton(); } private void button1_click(object sender, eventargs e) { clicks = clicks - cost; diamondsscore.text = "diamonds: " + clicks.tostring(); timer1.enabled = true; updatebutton(); button1.enabled = false; interval *= factor; timer1.interval = (int)interval; cost++; label2.text = "cost: " + cost.tostring() + "$"; } private void button2_click(object sender, eventargs e) { clicks = clicks - cost2; diamondsscore.text = "diamonds: " + clicks.tostring(); timer2.enabled = true; updatebutton2(); button2.enabled = false; interval *= factor; timer2.interval = (int)interval; cost2++; label4.text = "cost: " + cost2.tostring() + "$"; } private void timer2_tick(object sender, eventargs e) { counter++; clicks = clicks + 10; diamondsscore.text = "diamonds: " + clicks.tostring(); updatebutton2(); } } }
add following line in button2_click method
cost2 += 10;
Comments
Post a Comment