Ejemplo n.º 1
0
        //load file
        private void button1_Click(object sender, EventArgs e)
        {
            Inventory tempInven = new Inventory();

            inventory.player      = tempInven.player;
            inventory             = tempInven;
            inventory.playerItems = tempInven.playerItems;
            OpenFileDialog open = new OpenFileDialog();

            open.Title  = "Load a file";
            open.Filter = "Text File | *.txt";
            if (open.ShowDialog() == DialogResult.OK)
            {
                StreamReader reader = new StreamReader(open.FileName);
                string       s      = "";

                List <string> lines = new List <string>();

                while ((s = reader.ReadLine()) != null)
                {
                    lines.Add(s);
                }

                if (lines[0] == "Fighter")
                {
                    Fighter fighter = new Fighter(lines[1]);
                    fighter.maxhp     = int.Parse(lines[2]);
                    fighter.currenthp = int.Parse(lines[3]);
                    fighter.mp        = int.Parse(lines[4]);
                    fighter.str       = int.Parse(lines[5]);
                    fighter.level     = int.Parse(lines[6]);
                    fighter.exp       = int.Parse(lines[7]);
                    fighter.progress  = int.Parse(lines[8]);
                    inventory.player  = fighter;
                }
                else if (lines[0] == "Wizard")
                {
                    Wizard fighter = new Wizard(lines[1]);
                    fighter.maxhp     = int.Parse(lines[2]);
                    fighter.currenthp = int.Parse(lines[3]);
                    fighter.mp        = int.Parse(lines[4]);
                    fighter.str       = int.Parse(lines[5]);
                    fighter.level     = int.Parse(lines[6]);
                    fighter.exp       = int.Parse(lines[7]);
                    fighter.progress  = int.Parse(lines[8]);
                    inventory.player  = fighter;
                }
                inventory.playerGold = int.Parse(lines[9]);

                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i] == "@")
                    {
                        switch (int.Parse(lines[i + 1]))
                        {
                        case 0:
                            Potions potion = new Potions(lines[i + 2], int.Parse(lines[i + 3]), int.Parse(lines[i + 4]), int.Parse(lines[i + 5]), int.Parse(lines[i + 6]), lines[i + 7], decimal.Parse(lines[i + 8]), decimal.Parse(lines[i + 9]));
                            inventory.playerItems.Add(potion);
                            break;

                        case 1:
                            string  name        = lines[i + 2];
                            int     hp          = int.Parse(lines[i + 3]);
                            int     str         = int.Parse(lines[i + 4]);;
                            int     mp          = int.Parse(lines[i + 5]);
                            int     rounds      = int.Parse(lines[i + 6]);
                            string  description = lines[i + 7];
                            decimal cost        = decimal.Parse(lines[i + 8]);
                            decimal sellprice   = decimal.Parse(lines[i + 9]);

                            Weapon weapon = new Weapon(name, str, mp, cost, description, sellprice);
                            inventory.playerItems.Add(weapon);
                            break;
                        }
                    }
                }
                //spells
                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i] == "$$")
                    {
                        string  name        = lines[i + 1];
                        int     mp          = int.Parse(lines[i + 2]);
                        int     str         = int.Parse(lines[i + 3]);;
                        int     hp          = int.Parse(lines[i + 4]);
                        string  description = lines[i + 5];
                        int     rounds      = int.Parse(lines[i + 6]);
                        int     spellType   = int.Parse(lines[i + 7]);
                        int     itemType    = int.Parse(lines[i + 8]);
                        decimal cost        = decimal.Parse(lines[i + 10]);
                        decimal sellprice   = decimal.Parse(lines[i + 9]);

                        Spells spell = new Spells(name, mp, hp, str, rounds, spellType, description, cost, sellprice);
                        inventory.spells.Add(spell);
                    }
                }


                this.Close();
                thread = new Thread(openTown);
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
        }
Ejemplo n.º 2
0
 //buf checker
 public void spellRoundUpdate(object sender, SpellRounds e)
 {
     buffRound = e.currentRound;
     buff      = e.activeSpell;
     active    = true;
 }
Ejemplo n.º 3
0
        //back button
        private void btnBack_Click(object sender, EventArgs e)
        {
            buttonClick();

            switch (progression)
            {
            case 1:
                progression = 0;
                break;

            case 2:
                progression = 0;
                break;

            case 3:
                progression = 1;
                break;

            case 4:
                progression = 1;
                break;

            case 5:
                progression = 3;
                break;

            case 6:
                if (basWin == false)
                {
                    MessageBox.Show("As you start to turn back you hear a ear piercing growl coming from the right! You turn and barely dodge a tail whip from a Basilisk!");
                    MessageBox.Show("You have no choice but to turn and face the beast!");
                    Monster bas   = new Monster("Basilisk", 75, 10, 13, 1, "sunk it's fangs into you", "tail whipped you");
                    bool    dub   = false;
                    Fight   fight = new Fight(inventory, bas, dub);
                    fight.specialWin += special;
                    fight.ShowDialog();

                    if (specialWin == true)
                    {
                        if (inventory.player is Fighter)
                        {
                            Weapon claws = new Weapon("Claws", 15, 0, 0, "Wearable claws that deal up to 15 damage", 70);
                            inventory.playerItems.Add(claws);
                            MessageBox.Show($"After defeating the Basilisk the body deterates leaving nothing but the beast's claws behind!");
                            MessageBox.Show($"{claws.Name} has been added to your inventory!");
                        }
                        else if (inventory.player is Wizard)
                        {
                            Spells rockFall = new Spells("Rock fall", 12, 0, 0, 0, 0, "Summons rocks above the targets hits and deal up to 12 damage", 0, 70);
                            inventory.spells.Add(rockFall);
                            MessageBox.Show($"After defeating the Basilisk a mystical force overwhemls you and you gain a new power");
                            MessageBox.Show($"{rockFall.Name} has been added to your spell list!");
                        }

                        basWin         = true;
                        specialWin     = false;
                        btnOne.Visible = false;

                        MessageBox.Show("Congratulation you beat the first level!");
                        progression = 1;

                        this.Close();
                        thread = new Thread(openTown);
                        thread.SetApartmentState(ApartmentState.STA);
                        thread.Start();
                    }
                }
                break;
            }
            progressionChange();
        }
Ejemplo n.º 4
0
        //use  a spell
        private void btnUse_Click(object sender, EventArgs e)
        {
            //if they user selected a spell
            if (cmbSpells.SelectedIndex != -1)
            {
                Spells temp = new Spells("", 0, 0, 0, 0, 0, "", 0, 0);
                temp = spells[cmbSpells.SelectedIndex];
                Random rng = new Random();
                switch (temp.SpellType)
                {
                //if spell only deals damage
                case 0:
                    int spellDamage = rng.Next(0, temp.Mp + 1);
                    int damage      = (rng.Next(0, inventory.player.mp + 1) + spellDamage);
                    //if attack misses
                    if (damage > 0)
                    {
                        currentMonster.CurrentHp = currentMonster.CurrentHp - damage;
                        MessageBox.Show($"You dealt {damage} to the {currentMonster.Name}!");
                    }
                    else
                    {
                        MessageBox.Show($"{spells[cmbSpells.SelectedIndex].Name} missed!");
                    }

                    break;

                //if spell is a buff
                case 1:
                    if (temp.Mp > 0 && temp.Str < 0)
                    {
                        inventory.player.mp = inventory.player.mp + temp.Mp;
                        MessageBox.Show($"Your mp was increased by {temp.Mp} for {temp.Rounds}");
                    }
                    else if (temp.Str > 0 && temp.Mp < 0)
                    {
                        inventory.player.str = inventory.player.str + temp.Str;
                        MessageBox.Show($"Your str was increased by {temp.Str} for {temp.Rounds}");
                    }
                    else if (temp.Str > 0 && temp.Mp > 0)
                    {
                        inventory.player.str = inventory.player.str + temp.Str;
                        inventory.player.mp  = inventory.player.mp + temp.Mp;
                        MessageBox.Show($"Your str was increased by {temp.Str} and your mp was increased by {temp.Mp} for {temp.Rounds}");
                    }
                    break;

                //if spell restores hp
                case 2:
                    if (temp.Health > 0)
                    {
                        inventory.player.currenthp = inventory.player.currenthp + temp.Health;
                        if (inventory.player.currenthp > inventory.player.maxhp)
                        {
                            inventory.player.currenthp = inventory.player.maxhp;
                        }

                        MessageBox.Show($"Your health has been restored to {inventory.player.currenthp}");
                    }
                    break;
                }
                SpellRounds spelRounds = new SpellRounds();
                spelRounds.rounds       = temp.Rounds;
                spelRounds.currentRound = currentRound;
                spelRounds.activeSpell  = temp;
                spellRounds?.Invoke(this, spelRounds);
            }

            this.Close();
        }