Esempio n. 1
0
        private void btnFight_Click(object sender, EventArgs e)
        {
            Hero     h = myHero[cbxHero.SelectedIndex];
            Vilain   v = myVillians[cbxVillian.SelectedIndex];
            SideKick s = mySidekick[cbxSide.SelectedIndex];

            double heroHealth = h.Health;
            double villHealth = v.Health;
            double sideHealth = s.Health;

            int chanceTotal = h.Chance + v.Chance + s.Chance;

            bool over = true;

            while (over)
            {
                Random r   = new Random();
                int    num = r.Next(1, chanceTotal);
                if (num <= h.Chance)
                {
                    rtbFight.AppendText("\nHero Attacked\n");
                    villHealth -= h.Attack;
                }
                else if ((num > h.Chance) && (num <= v.Chance))
                {
                    rtbFight.AppendText("\nVillan Attacked\n");
                    heroHealth -= v.Attack;
                    sideHealth -= v.Attack;
                }
                else
                {
                    rtbFight.AppendText("\nSidekick Attacked\n");
                    villHealth -= s.Attack;
                }

                rtbFight.AppendText("=======================\n");
                rtbFight.AppendText("Hero Health: " + heroHealth);
                rtbFight.AppendText("\nSidekick Health: " + sideHealth);
                rtbFight.AppendText("\nVillain Health: " + villHealth);
                rtbFight.AppendText("\n=======================\n\n");

                if (heroHealth < 0 && sideHealth < 0)
                {
                    rtbFight.AppendText("\nVillain has won\n");
                    over = false;
                }
                else if (villHealth < 0)
                {
                    rtbFight.AppendText("\nHeros have won\n");
                    over = false;
                }

                Thread.Sleep(200);
            }
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Adding new characters
            if (lbxTypes.SelectedIndex == 0)
            {
                Hero h = new Hero(txtAlias.Text, double.Parse(txtHealth.Text), int.Parse(txtAttack.Text), int.Parse(txtChance.Text));
                myHero.Add(h);
                fh.Write("hero.txt", new List <string> {
                    h.ToString()
                }, false);
                //bool x = false : so the file is appended and NOT overwritten True = Overwite existing data
            }
            else if (lbxTypes.SelectedIndex == 1)
            {
                Vilain v = new Vilain(txtAlias.Text, double.Parse(txtHealth.Text), int.Parse(txtAttack.Text), int.Parse(txtChance.Text));
                myVillians.Add(v);
                fh.Write("villain.txt", new List <string> {
                    v.ToString()
                }, false);
            }
            else
            {
                SideKick s = new SideKick(txtAlias.Text, double.Parse(txtHealth.Text), int.Parse(txtAttack.Text), int.Parse(txtChance.Text));
                mySidekick.Add(s);
                fh.Write("sidekick.txt", new List <string> {
                    s.ToString()
                }, false);
            }

            MessageBox.Show("Added");

            txtAlias.Clear();
            txtAttack.Clear();
            txtChance.Clear();
            txtHealth.Clear();

            DisplayInComboBox();
        }