| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 700 人关注过本帖
标题:新人求助有关类问题
只看楼主 加入收藏
姓张名世离
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2019-10-17
结帖率:60%
收藏
 问题点数:0 回复次数:7 
新人求助有关类问题
附件: 游客没有浏览附件的权限,请 登录注册
2020-10-13 10:49
姓张名世离
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2019-10-17
收藏
得分:0 
有偿代写。
2020-10-18 20:26
venomlk
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-2-18
收藏
得分:0 
除了hp<=0死亡不知怎么处理外(或着说不清楚具体要怎么做?是要删除此人信息?),其它需求都实现了(年龄、性别等是固定写死的,没有做其它处理)

个人信息:显示的是当前操作的人员信息
添加人员:可添加“worker、theif”两个类型的人员
工作:hp-1同时money+1
娱乐:money-1同时hp+1(或+2)
偷窃:需要先在左边的下拉框选择被偷窃的人员名字
查询:查询已添加人员中的某一个人的信息(需要先在左边的下拉框选择需要查询的人员名字)
附件: 游客没有浏览附件的权限,请 登录注册
2020-10-21 09:43
venomlk
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2009-2-18
收藏
得分:0 
    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]);
        }
2020-10-21 09:53
姓张名世离
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2019-10-17
收藏
得分:0 
回复 3楼 venomlk
感谢帮助。
2020-10-22 22:27
姓张名世离
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2019-10-17
收藏
得分:0 
回复 4楼 venomlk
感谢帮助
2020-10-22 22:27
neixun
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-10-23
收藏
得分:0 
666
2020-10-24 11:29
快速回复:新人求助有关类问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.062022 second(s), 8 queries.
Copyright©2004-2020, BCCN.NET, All Rights Reserved