在编码C#时,我会说一个新东西,因此,我不会太过严。 我在《大本》前用行动编号,并指出它非常相似。
无论如何,在两种特性相互“金钱”的情况下,我基本上需要建立简单的应用。 特征名称应是动态的,各纽州应在名称之外发挥作用。
请帮助! 这是我迄今为止所做的:
namespace Lab_2
{
public partial class Form1 : Form
{
Guy firstName;
Guy secondName;
int bank = 100;
public Form1()
{
InitializeComponent();
firstName = new Guy() { Cash = 100, Name = "Joe" };
secondName = new Guy() { Cash = 50, Name = "Bob" };
firstName = textBox1.Text;
secondName = textBox2.Text;
UpdateForm();
}
public void UpdateForm()
{
name1CashLabel.Text = firstName.Name + " has $" + firstName.Cash;
name2CashLabel.Text = secondName.Name + " has $" + secondName.Cash;
bankCashLabel.Text = "The bank has $" + bank;
}
private void button1_Click(object sender, EventArgs e)
{
button1.Text = "Give $10 to " + firstName.Name;
if (bank >= 10)
{
bank -= firstName.ReceiveCash(10);
UpdateForm();
}
else
{
MessageBox.Show("The bank is out of money.");
}
}
private void button2_Click(object sender, EventArgs e)
{
bank += secondName.GiveCash(5);
UpdateForm();
}
private void button3_Click(object sender, EventArgs e)
{
secondName.ReceiveCash(firstName.GiveCash(10));
UpdateForm();
}
private void button4_Click(object sender, EventArgs e)
{
firstName.ReceiveCash(secondName.GiveCash(5));
UpdateForm();
}
private void name1_Click(object sender, EventArgs e)
{
firstName.Name = textBox1.Text;
}
}
}