Ejemplo n.º 1
0
        /// <summary>
        /// Combat method that does the combat automatically based on atk and defense on both you and the enemy.
        /// </summary>
        private void Combat()
        {
            string message;

            if (!defend)
            {
                Gamehandler.DoDamage(classes, enemies, lblEnemy.Content.ToString(), poison, out message);
                ConsoleMessage(message);
                if (poison > 0)
                {
                    poison--;
                }
            }
            Gamehandler.TakeDamage(classes, enemies, lblEnemy.Content.ToString(), defence, out message);
            ConsoleMessage(message);

            Rewards();
            listConsole.SelectedIndex = listConsole.Items.Count - 1;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// I decided to save it in different ways, with both TXT and XML. I save the weapons to the xml-file and all the other game status informations to a textfile
        /// This method takes all information and saves it in different ways.
        /// </summary>
        private void Serialize()
        {
            List <string> saver = new List <string>();

            saver.Add(((Classes)classes).GetChangedDamage().ToString()); //TODO CHANGE TO CLASSES HEALTH AND DMDG
            saver.Add(((Classes)classes).GetChangedHealth().ToString());
            saver.Add(((Classes)classes).GetChangedDefence().ToString());
            saver.Add(specialWaitTime.ToString());
            saver.Add(waitTime.ToString());

            saver.Add(cmbItem.Items.Count.ToString());
            for (int i = 0; i < cmbItem.Items.Count; i++)
            {
                saver.Add(cmbItem.Items.GetItemAt(i).ToString());
            }

            saver.Add(lvl.ToString());
            saver.Add(experience.ToString());
            saver.Add(gold.ToString());



            saver.Add(((Classes)classes).GetName());
            for (int i = 0; i < listConsole.Items.Count; i++)
            {
                saver.Add(listConsole.Items.GetItemAt(i).ToString());
            }

            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.ShowDialog();
            string fileName = saveFile.FileName;

            Gamehandler.TextFileSerialize <string>(fileName + ".txt", saver);

            Gamehandler.WriteToXMLFile <List <int> >(fileName + ".xml", weaponDamage);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// loads all information from the textfile and XML file to a list and then sends it off to the mainform inform of a list.
        ///
        /// Using two different file openings is a choice.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnLoad_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Title  = "Select a .txt file";
            open.Filter = "Text|*.txt|All|*.*";
            open.ShowDialog();
            string fileName = open.FileName;


            OpenFileDialog open2 = new OpenFileDialog();

            open2.Title  = "Select a .xml file";
            open2.Filter = "XML|*.xml|All|*.*";
            open2.ShowDialog();
            string        fileName2 = open2.FileName;
            List <string> textList  = new List <string>();

            if (!string.IsNullOrEmpty(fileName) || !string.IsNullOrEmpty(fileName2))
            {
                textList = Gamehandler.ReadFromTextFile(fileName);
                try
                {
                    if (textList.Count > 4)
                    {
                        int        x    = 6;
                        GameWindow main = new GameWindow();
                        for (int i = 0; i < 5; i++)
                        {
                            saveList.Add(Convert.ToInt32(textList[i]));
                        }

                        int count = Convert.ToInt32(textList[5]);
                        for (int i = 0; i <= count - 1; i++)
                        {
                            main.AddToComboBox(textList[x]);
                            x++;
                        }
                        main.Lvl = Convert.ToInt32(textList[x]);
                        x++;
                        main.Experience = Convert.ToInt32(textList[x]);
                        x++;
                        main.Gold = Convert.ToInt32(textList[x]);
                        x++;
                        main.InitializeGUI(textList[x], true, saveList);
                        x++;

                        for (int i = x; i < textList.Count; i++)
                        {
                            main.ConsoleMessage(textList[i]);
                        }


                        main.WeaponDamage = Gamehandler.ReadXMLFile <List <int> >(fileName2);
                        main.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Textfile does not contain proper syntax and could not be loaded", "error");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Textfile does not contain proper syntax");
                }
            }
            else
            {
                MessageBox.Show("You did not select any files", "Error ");
            }
        }