I'm a newbie when it comes to coding C#, so please don't be too harsh on me. I've coded with ActionScript before, and notice that it's very similar.
Anyway, I need to basically build a simple application where 2 characters give each other "money"... or ints. The character name should be dynamic, and the buttons should play off of what the names are.
Please help! This is what I have so far:
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;
}
}
}