[英]c# Idle Game; Adding money issue
我目前仅在使用ac#(无Unity)空闲游戏(又名Clicker游戏)上工作,在该游戏中,用户通过单击按钮并升级金矿来筹集资金,下面是代码;
namespace Business_Tycoon
{
public partial class Form1 : Form
{
public decimal level;
public decimal money;
public decimal revenue;
public decimal multiplier;
public decimal price;
public Form1()
{
InitializeComponent();
start();
}
void start()
{
money = 10;
}
void update()
{
money = money + revenue;
}
void button1_Click(object sender, EventArgs e)
{
price = ((price/100) * 150m);
level = (level + 1);
multiplier = 1.10m;
money = (money - price);
revenue = (level * multiplier);
button1.Text = "Price: " + price;
textBox1.Text = "Item Bought";
label4.Text = "Money: " + Convert.ToString(money);
label1.Text = "Level: " + Convert.ToString(level);
label3.Text = "Revenue: " + Convert.ToString(revenue);
}
private void button2_Click(object sender, EventArgs e)
{
update();
}
}
}
但是,要从Button2收集游戏,玩家必须先单击Button1才能将其升级,但我不知道该如何解决。 玩家应该能够单击“收集”按钮并添加金矿的任何收入。
请提供帮助,谢谢-Maximus
我不太了解您的问题。 如果用户单击Button2,那会发生什么? 如果要强制用户首先单击Button1,则可以将Button2默认设置为禁用,并在单击Button1时将其翻转为启用。 让我知道如何提供帮助。
尝试以下方法,这应该是有道理的。 您需要初始化变量并使用线程进行更新。 我使用了计时器,因为它是最简单的可用资源。
public partial class Form1 : Form {
public decimal level { get; set; }
public decimal money { get; set; }
public decimal revenue { get; set; }
public decimal multiplier { get; set; }
public decimal price { get; set; }
private Timer Updater { get; set; }
public Form1() {
InitializeComponent();
Updater = new Timer();
Start();
}
void Start() {
money = 10;
multiplier = 1.10m;
price = 5;
label1.Text = "Level: " + money.ToString();
label3.Text = "Revenue: " + revenue.ToString();
button1.Text = "Price: " + price.ToString();
label4.Text = "Money: " + money.ToString();
Updater.Interval = 1000; //interval in milliseconds || this will tick every second
Updater.Tick += Updater_Tick;
Updater.Start();
}
private void Updater_Tick(object sender, EventArgs e) {
money += revenue;
label4.Text = "Money: " + money.ToString();
}
void button1_Click(object sender, EventArgs e) {
if (money >= price) {
money -= price;
price = ((price/100)*150m);
button1.Text = "Price: " + price.ToString();
level++;
label1.Text = "Level: " + money.ToString();
label3.Text = "Revenue: " + revenue.ToString();
revenue = level*multiplier;
textBox1.Text = "Item Bought";
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.