zoukankan      html  css  js  c++  java
  • 类例程_c#战斗程序(窗体版)

    战士类代码:

    class Fight
        {
            String name;
            int  attack, speed, crit, armor;// 生命、攻击力,攻速,暴击,护甲
            public int life;
            public Form1 main_Form;
            public void set_MainForm(Form1 x)
            {
                main_Form = x;
            }
    
            public void set_Fight(String a, int a1, int a2, int a3, int a4, int a5)//可改为构造函数
            {
                name = a;
                life = a1;
                attack = a2;
                speed = a3;
                crit = a4;
                armor = a5;
            }
    
            public void attack_Sb(Fight x)
            {
                int send_attack;
                Random r1 = new Random();
                if (r1.Next(100) <= crit)
                {
                    send_attack = attack * speed * 2;
                }
                else
                {
                    send_attack = attack * speed;
                }
                main_Form.set_Text(name + "发出攻击:" + send_attack);
                x.be_Attack(send_attack);
            }
    
            public void be_Attack(int x)
            {
                life = (int)(life - x * 100.0 / (100 + armor));
                show_Me();
            }
            void show_Me()
            {
                main_Form.set_Text(name + ",life:" + life);
            }
        }
    

      窗体调用代码:

    private void button1_Click(object sender, EventArgs e)
            {
                Fight shoot, soldier;
                shoot = new Fight();
                soldier = new Fight();
                shoot.set_MainForm(this);
                soldier.set_MainForm(this);
                shoot.set_Fight("射手", 300, 75, 2, 10, 30);
                soldier.set_Fight("战士", 500, 90, 1, 20, 45);
                textBox1.Text = "";
                while (true)
                {
                    shoot.attack_Sb(soldier);
                    if (soldier.life <= 0)
                    {
                        break;
                    }
                    soldier.attack_Sb(shoot);
                    if (shoot.life <= 0)
                    {
                        break;
                    }
                    set_Text("------------");
                }
            }
            public void set_Text(string s)
            {
                textBox1.Text += "
    " + s;
            }
    

      

  • 相关阅读:
    Vue监听器、过滤器
    Vue生命周期、计算属性
    数组去重
    ES6总结
    学习笔记--html篇(1)
    学习整理--flex布局(1)
    对块作用域与变量函数提升再添新认识
    了解使用web workers
    js中的事件循环模型与特殊的定时器
    操作系统、浏览器与js之间的一些概念与联系
  • 原文地址:https://www.cnblogs.com/wanjinliu/p/11001033.html
Copyright © 2011-2022 走看看