class Person
//person类
{
public string name = "", gender = "", birthday = "", state = "";
public int age = 0, money = 0, HP = 0;
public virtual void Rest()
{
money--;
HP++;
}
}
class Worker:Person
//worker类
{
public string JobDate = "";
public Worker(string name, int money, int HP)
{
this.name = name;
this.money = money;
this.HP = HP;
age = 26;
gender = "女";
state = "Worker";
}
public void work()
{
money++;
HP--;
}
public override void Rest()
{
money--;
HP += 2;
}
}
class Theif:Person
//theif类
{
public string JobDate = "";
public Theif(string name, int money, int HP)
{
this.name = name;
this.money = money;
this.HP = HP;
age = 30;
gender = "男";
state = "Theif";
}
public void steal(Person p)
{
p.money--;
money++;
HP--;
}
}
Dictionary<string, Person> parr = new Dictionary<string, Person>();
private void button2_Click(object sender, EventArgs e)
//添加人员
{
if (comboBox2.Text != "" & textBox1.Text != "")
{
if (comboBox2.Text == "Worker")
{
if (!parr.ContainsKey(textBox1.Text))
{
parr.Add(textBox1.Text, new Worker(textBox1.Text, 100, 100));
}
}
else
{
if (comboBox2.Text == "Theif")
{
if (!parr.ContainsKey(textBox1.Text))
{
parr.Add(textBox1.Text, new Theif(textBox1.Text, 100, 100));
}
}
}
comboBox1.Items.Add(textBox1.Text);
comboBox3.Items.Add(textBox1.Text);
xx(parr[textBox1.Text]);
}
else { MessageBox.Show("必须填写姓名和职业"); }
}
private void xx(Person p)
//个人信息
{
label2.Text = p.name;
label4.Text = p.age.ToString();
label6.Text = p.gender;
label8.Text = p.HP.ToString();
label10.Text = p.money.ToString();
label12.Text = p.state;
}
private void button3_Click(object sender, EventArgs e)
//工作
{
if (label12.Text == "Worker")
{
Worker w = parr[label2.Text] as Worker;
w.work();
xx(w);
}
else
{
MessageBox.Show("没有此技能");
}
}
private void button4_Click(object sender, EventArgs e)
//娱乐
{
Person p;
if (label12.Text == "Worker")
{
p = parr[label2.Text] as Worker;
}
else
{
p = parr[label2.Text] as Theif;
}
p.Rest();
xx(p);
}
private void button5_Click(object sender, EventArgs e)
//偷窃
{
if (comboBox3.Text != "" & comboBox3.Text != label2.Text)
{
if (label12.Text == "Theif")
{
Theif t = parr[label2.Text] as Theif;
t.steal(parr[comboBox3.Text] as Person);
xx(t);
}
else
{
MessageBox.Show("没有此技能");
}
}
else
{
MessageBox.Show("需要选择偷窃对象人员名字");
}
}
private void button1_Click(object sender, EventArgs e)
//查询信息
{
xx(parr[comboBox1.Text]);
}