Пример #1
0
        private static Dictionary <uint, Guild> guildList   = new Dictionary <uint, Guild>();   // Player dictionary.

        public Form1()
        {
            InitializeComponent();

            // Start the background music.
            music.Play();

            // Build Guild dictionary
            using (var reader = new StreamReader(@"..\..\..\Resources\guilds.txt")) {
                string line;        // Single entry in guilds.txt file.

                // While there are still lines to be read from guilds file, tokenize each line and add each guild to guildList dictionary.
                while ((line = reader.ReadLine()) != null)
                {
                    // Split line to isolate the guild ID.
                    string[] guildTokens = line.Split('\t');

                    // Convert gild ID from string to unsigned int.
                    uint guildId = Convert.ToUInt32(guildTokens[0]);

                    // Split second part of line into guild name and guild server.
                    string[] guildInfo = guildTokens[1].Split('-');

                    string guildName   = guildInfo[0];
                    string guildServer = guildInfo[1];

                    // Make a Guild object. Just send 0 for last argument since guilds from the file have yet to have a guild Type (Raiding, PVP, etc...).
                    Guild guild = new Guild(guildId, guildName, guildServer, 0);

                    // Finally, add guild to guildList dictionary.
                    guildList.Add(guildId, guild);
                    guildId++;
                }
            }

            // Build Player dictionary
            using (var reader = new StreamReader(@"..\..\..\Resources\players.txt")) {
                string line;

                while ((line = reader.ReadLine()) != null)
                {
                    string[] itemTokens = line.Split('\t');

                    //uint id, string name, Race race, Class class, uint level, uint exp, uint guildID
                    Player player = new Player(
                        Convert.ToUInt32(itemTokens[0]),
                        itemTokens[1],
                        (Race)Convert.ToUInt32(itemTokens[2]),
                        (CharClass)Convert.ToUInt32(itemTokens[3]),
                        Convert.ToUInt32(itemTokens[4]),
                        Convert.ToUInt32(itemTokens[5]),
                        Convert.ToUInt32(itemTokens[6])
                        );

                    playerList.Add(Convert.ToUInt32(itemTokens[0]), player);
                    playerId++;
                }
            }

            // Populate guild list.
            foreach (KeyValuePair <uint, Guild> entry in guildList)
            {
                listBoxGuilds.Items.Add(String.Format("{0, -20}\t[{1, -5}]\n", entry.Value.Name, entry.Value.Server));
            }

            // Populate player list.
            foreach (KeyValuePair <uint, Player> entry in playerList)
            {
                listBoxPlayers.Items.Add(String.Format("{0, -17}\t{1, -11} {2, -5}\n", entry.Value.Name, entry.Value.CharClass, entry.Value.Level));
            }

            // Populate server comboBox.
            comboBoxServer.Items.Add(Server.Beta4Azeroth);
            comboBoxServer.Items.Add(Server.TKWasASetback);
            comboBoxServer.Items.Add(Server.ZappyBoi);

            // Populate create player comboBoxes.
            comboBoxRace.Items.Add(Race.Forsaken);
            comboBoxRace.Items.Add(Race.Orc);
            comboBoxRace.Items.Add(Race.Tauren);
            comboBoxRace.Items.Add(Race.Troll);

            comboBoxClass.Items.Add(CharClass.Warrior);
            comboBoxClass.Items.Add(CharClass.Mage);
            comboBoxClass.Items.Add(CharClass.Druid);
            comboBoxClass.Items.Add(CharClass.Priest);
            comboBoxClass.Items.Add(CharClass.Warlock);
            comboBoxClass.Items.Add(CharClass.Rogue);
            comboBoxClass.Items.Add(CharClass.Paladin);
            comboBoxClass.Items.Add(CharClass.Hunter);
            comboBoxClass.Items.Add(CharClass.Shaman);

            // Populate create guild comboBoxes.
            comboBoxGServer.Items.Add(Server.Beta4Azeroth);
            comboBoxGServer.Items.Add(Server.TKWasASetback);
            comboBoxGServer.Items.Add(Server.ZappyBoi);

            comboBoxGType.Items.Add(GuildType.Casual);
            comboBoxGType.Items.Add(GuildType.Mythic);
            comboBoxGType.Items.Add(GuildType.PVP);
            comboBoxGType.Items.Add(GuildType.Questing);
            comboBoxGType.Items.Add(GuildType.Raiding);
        }
Пример #2
0
        /*
         *  Method:     buttonAddGuild_Click
         *
         *  Purpose:    Handles when the user clicks "Add Guild" button.
         *
         *  Arguments:  object      The publisher of the event.
         *              EventArgs   Event data from the publisher.
         */
        private void buttonAddGuild_Click(object sender, EventArgs e)
        {
            bool sameNameError     = false;
            bool missingFieldError = false;

            // Reset output field to blank.
            richTextOutput.Clear();

            // Error message for when user doesn't put in values in the player creation fields.
            StringBuilder errorMessage = new StringBuilder("Could not create guild: ");

            // Check if guild name already exsits.
            if (textBoxGName.Text != "")
            {
                // Loop through list of guilds to see if name is taken already.
                foreach (KeyValuePair <uint, Guild> guild in guildList)
                {
                    // If duplicate name is found, flag it and add to error message.
                    if (textBoxGName.Text.Equals(guild.Value.Name))
                    {
                        sameNameError = true;

                        errorMessage = new StringBuilder(errorMessage + "\n\u2022 Guild name already taken.");
                        break;
                    }
                }
            }

            // If player doesn't add information to a field(s), display a warning message in the Output with missing fields listed.
            if (textBoxGName.Text == "" || comboBoxGServer.SelectedIndex == -1 || comboBoxGType.SelectedIndex == -1)
            {
                if (textBoxGName.Text == "")
                {
                    errorMessage = new StringBuilder(errorMessage + "\n\u2022 Missing guild Name ");
                }

                if (comboBoxGServer.SelectedIndex == -1)
                {
                    errorMessage = new StringBuilder(errorMessage + "\n\u2022 Missing guild Server ");
                }

                if (comboBoxGType.SelectedIndex == -1)
                {
                    errorMessage = new StringBuilder(errorMessage + "\n\u2022 Missing guild Type ");
                }

                missingFieldError = true;
            }

            // If any form error detected, display error message in Output field.
            if (sameNameError || missingFieldError)
            {
                richTextOutput.Text = errorMessage.ToString();
            }

            if (!sameNameError && !missingFieldError)   // Add the guild to the system.

            {
                while (guildList.ContainsKey(guildId))
                {
                    guildId++;
                }

                // Make a new Guild object with data from form fields.
                Guild newGuild = new Guild(guildId, textBoxGName.Text, comboBoxGServer.SelectedItem.ToString(), 0);

                // Add the new player to the players dictionary (Key: guildId  Value: newGuild).
                guildList.Add(guildId, newGuild);

                // Clear player list in the form to make way for the updated list.
                listBoxGuilds.Items.Clear();

                // Display the new player list by adding the updated Guild dictionary.
                foreach (KeyValuePair <uint, Guild> entry in guildList)
                {
                    listBoxGuilds.Items.Add(String.Format("{0, -20}\t[{1, -5}]\n", entry.Value.Name, entry.Value.Server));
                }

                richTextOutput.Text = String.Format(String.Format("{0} guild has been added. \n", textBoxGName.Text));

                // Reset player creation fields to blank.
                textBoxGName.Text             = "";
                comboBoxGServer.SelectedIndex = -1;
                comboBoxGType.SelectedIndex   = -1;

                // Increment guild ID by one for the next new guild.
                guildId++;
            }
        }