Пример #1
0
        private void StartMenu_StartGame_Click(object sender, EventArgs e)
        {
            string[] file;
            if (File.Exists(@"D:\\HeroWarsSaves.txt"))
            {
                file = File.ReadAllLines(@"D:\\HeroWarsSaves.txt");

                if (file.Length >= 1)
                {
                    this.Hide();
                    Saves saves = new Saves();
                    saves.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("No characters found! Please create a character!");
                    this.Hide();
                    CharacterCreator createcharacter = new CharacterCreator();
                    createcharacter.ShowDialog();
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("No characters found! Please create a character!");
                this.Hide();
                CharacterCreator createcharacter = new CharacterCreator();
                createcharacter.ShowDialog();
                this.Close();
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            UpdateHeroInfo();
            save.UpdateSaved();

            this.Hide();
            Saves saves = new Saves();

            saves.ShowDialog();
            this.Close();
        }
Пример #3
0
        private void CC_Create_Click(object sender, EventArgs e)
        {
            Save   save   = new Save();
            string Name   = "";
            string Gender = "";

            try
            {
                save.RefreshCharNames();

                for (int i = 0; i < CC_NameBox.Text.Length; i++)
                {
                    if (!((char)CC_NameBox.Text[i] >= 65 && (char)CC_NameBox.Text[i] <= 90) &&
                        !((char)CC_NameBox.Text[i] >= 97 && (char)CC_NameBox.Text[i] <= 122))
                    {
                        MessageBox.Show("Your hero name must not contain numbers or special characters!");
                        throw new Exception();
                    }
                }
                if (!CC_NameBox.Text.Any(char.IsDigit) && CC_NameBox.Text != "" && !(CC_NameBox.Text.Length > 18))
                {
                    bool contains = false;
                    if (!File.Exists(@"D:\\Names.txt"))
                    {
                        FileStream file = new FileStream(@"D:\\Names.txt", FileMode.Create, FileAccess.ReadWrite);
                        file.Close();
                    }
                    else
                    {
                        using (StreamReader readNames = File.OpenText(@"D:\\Names.txt"))
                        {
                            while (!readNames.EndOfStream)
                            {
                                string line = readNames.ReadLine();
                                if (CC_NameBox.Text == line)
                                {
                                    contains = true;
                                }
                            }
                            readNames.Close();
                        }
                    }
                    if (!contains)
                    {
                        Name = CC_NameBox.Text;
                    }
                    else
                    {
                        MessageBox.Show("Name already taken!");
                        throw new Exception("Name already taken!");
                    }
                }
                else
                {
                    if (CC_NameBox.Text.Length > 18)
                    {
                        MessageBox.Show("Name is too long!");
                        throw new Exception("Name is too long!");
                    }
                    else
                    {
                        MessageBox.Show("Invalid name. Please try again!");
                        throw new Exception("Invalid name!");
                    }
                }

                if (CC_Male.Checked)
                {
                    Gender = "Male";
                }
                else if (CC_Female.Checked)
                {
                    Gender = "Female";
                }
                else if (!CC_Male.Checked && !CC_Female.Checked && Gender == "")
                {
                    MessageBox.Show("Gender not selected!");
                    throw new Exception("Gender not selected!");
                }



                string race;
                if (CC_RaceList.SelectedItem == null)
                {
                    MessageBox.Show("Race not selected!");
                    throw new Exception("No race selected!");
                }
                else
                {
                    race = CC_RaceList.SelectedItem.ToString();
                }



                string _class;
                if (CC_ClassList.SelectedItem == null)
                {
                    MessageBox.Show("Class not selected!");
                    throw new Exception("No class selected!");
                }
                else
                {
                    _class = CC_ClassList.SelectedItem.ToString();
                }


                Hero player;

                if (race.ToString() == "Human")
                {
                    player = new Human(Name, Gender, _class);
                }
                else if (race.ToString() == "Elf")
                {
                    player = new Elf(Name, Gender, _class);
                }
                else
                {
                    player = new Dwarf(Name, Gender, _class);
                }


                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result  = MessageBox.Show("Are you sure?", "", buttons);
                if (result == DialogResult.Yes)
                {
                    string filePath     = @"D:\\HeroWarsSaves.txt";
                    string SaveContents = player.Name + "," + player.Gender + "," + player._Class + "," + player.Race +
                                          "," + player.Lvl + "," + player.Gold + "," + player.Dmg + "," + player.Health + "," + player.Wins;



                    using (FileStream file = new FileStream(filePath, FileMode.Append, FileAccess.Write))
                    {
                        StreamWriter sw = new StreamWriter(file);
                        sw.WriteLine(SaveContents);
                        sw.Close();
                    }

                    this.Hide();
                    Saves saves = new Saves();
                    saves.ShowDialog();
                    this.Close();
                }
                else
                {
                    return;
                }
            }
            catch
            { }
        }