예제 #1
0
        private static Weapon[] LoadWeapons(string filename)
        {
            Weapon[] tmpArr;

            string[] lines = File.ReadAllLines(filename);
            tmpArr = new Weapon[lines.Length - 1];
            for (int i = 1; i < lines.Length; i++)
            {
                string[] lineValues = lines[i].Split(',');

                if (lineValues[0] == "m")
                {
                    //Create a Melee weapon
                    //weapontype,name,type,damagemod,numberofhands,defaultdamage,age
                    Melee tmpMelee = new Melee();
                    tmpMelee.name = lineValues[1];
                    tmpMelee.type = lineValues[2];
                    int.TryParse(lineValues[3], out tmpMelee.damageModifier);

                    if (lineValues[4] != "")
                    {
                        int.TryParse(lineValues[4], out tmpMelee.numberHandsRequired);
                    }
                    if (lineValues[5] != "")
                    {
                        int.TryParse(lineValues[5], out tmpMelee.damage);
                    }
                    if (lineValues[6] != "")
                    {
                        int.TryParse(lineValues[6], out tmpMelee.age);
                    }
                    tmpArr[i - 1] = tmpMelee;
                }
                else
                {
                    //Assume it's a ranged.
                    Ranged tmpRanged = new Ranged();
                    tmpRanged.name = lineValues[1];
                    tmpRanged.type = lineValues[2];
                    int.TryParse(lineValues[3], out tmpRanged.damageModifier);

                    if (lineValues[4] != "")
                    {
                        int.TryParse(lineValues[4], out tmpRanged.numberHandsRequired);
                    }
                    if (lineValues[5] != "")
                    {
                        int.TryParse(lineValues[5], out tmpRanged.damage);
                    }
                    if (lineValues[6] != "")
                    {
                        int.TryParse(lineValues[6], out tmpRanged.age);
                    }
                    tmpArr[i - 1] = tmpRanged;
                }
            }

            return(tmpArr);
        }
예제 #2
0
        //TODO: Make this load from a file, or create a version that does.
        /// <summary>
        /// A very basic hard coded weapon load out
        /// </summary>
        /// <returns>an array of weapons</returns>
        private static Weapon[] SetupWeapons()
        {
            Weapon[] tmpArr = new Weapon[5];
            tmpArr[0] = new Melee();

            tmpArr[1] = new Melee("Excalibur the confused sword", "Two Handed Sword", 5, 2);
            tmpArr[2] = new Melee("Short sword", "One Handed Sword", 2);
            tmpArr[3] = new Ranged();

            tmpArr[4] = new Ranged(
                _name: "Super Bow",
                _type: "Enchanted Bow",
                _age: 20,
                _numberOfHands: 2
                );
            return(tmpArr);
        }