Ejemplo n.º 1
0
        //Check if bee is alive or dead
        public bool isDead(Bee bee)
        {
            if (bee.name == "Queen")
            {
                if (bee.health <= 20)
                {
                    return(true);
                }
            }
            else if (bee.name == "Worker")
            {
                if (bee.health <= 70)
                {
                    return(true);
                }
            }
            else if (bee.name == "Drone")
            {
                if (bee.health <= 50)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            Bee Worker = new Bee("Worker");
            Bee Queen  = new Bee("Queen");
            Bee Drone  = new Bee("Drone");

            listBox1.Items.Add(Worker);
            listBox1.Items.Add(Queen);
            listBox1.Items.Add(Drone);
        }
Ejemplo n.º 3
0
        //Bee Taking Damage
        public Bee damage(Bee bee, int damage)
        {
            //Subtract health first before checking if bee is dead
            bee.health = bee.health - damage;

            //while the bee is alive subtract damage
            while (!isDead(bee))
            {
                return(bee);
            }

            bee.health = 0;

            //if dead just return bee
            return(bee);
        }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            int amount = 15;

            Bee bee = (Bee)listBox1.SelectedItem;

            if (bee != null)
            {
                Bee damagedBee = bee.damage(bee, amount);

                if (damagedBee.health == 0)
                {
                    listBox2.Items.Add(damagedBee.name + " is dead");
                }
                else
                {
                    String currentBeeHealth = damagedBee.name + damagedBee.health.ToString();
                    listBox2.Items.Add(currentBeeHealth);
                }
            }
        }