Exemple #1
0
        /// <summary>
        /// Generates a custom sublocation
        /// </summary>
        /// <param name="id">ID of the sublocation</param>
        /// <param name="keys">Types of sublocations available</param>
        /// <param name="maxItems">Max items to be found at sublocation</param>
        /// <param name="maxAmount">Max amount of each item to be found at sublocation</param>
        /// <returns></returns>
        private Sublocation GenerateRandomSublocation(int id, List <String> keys, int maxItems, int maxAmount)
        {
            int    nextType = rnd.Next(keys.Count);
            String tempType = keys[nextType];

            return(SubLocationFactory.CreateSubLocation(tempType, id, maxItems, maxAmount));
        }
Exemple #2
0
        /// <summary>
        /// Generates a standard sublocation
        /// </summary>
        /// <param name="id">ID of the sublocation</param>
        /// <param name="keys">Types of sublocations available</param>
        /// <returns></returns>
        private Sublocation GenerateRandomSublocation(int id, List <String> keys)
        {
            int    nextType = rnd.Next(keys.Count);
            String tempType = keys[nextType];

            return(SubLocationFactory.CreateSubLocation(tempType, id, STD_MAX_ITEMS, STD_MAX_AMOUNT));
        }
Exemple #3
0
        /// <summary>
        /// Generates Sub Location with default constants
        /// </summary>
        public void GenerateSubLocations()
        {
            sublocations = new Dictionary <int, Sublocation>();
            var keys = SubLocationFactory.GetRegisteredTypes().ToList();

            for (int i = 1; i < STD_SIZE + 1; i++)
            {
                sublocations.Add(i, GenerateRandomSublocation(i, keys));
            }
            currentSubLocation = null;
        }
Exemple #4
0
        public Location(String toParse)
        {
            visited      = true;
            sublocations = new Dictionary <int, Sublocation>();
            String[] lElems = toParse.Split(',');
            foreach (String elem in lElems)
            {
                String[] locElem = elem.Split(':');
                switch (locElem[0])
                {
                case "ID":
                    int tempID;
                    int.TryParse(locElem[1], out tempID);
                    locationID = tempID;
                    break;

                case "Visited":
                    bool tempVis;
                    bool.TryParse(locElem[1], out tempVis);
                    visited = tempVis;
                    break;

                case "Sublocations":
                    if (locElem.Length > 1)
                    {
                        for (int i = 1; i < locElem.Length; i = i + 6)
                        {
                            Sublocation temp = SubLocationFactory.CreateSubLocation(locElem[i] + ":" + locElem[i + 1] + ":" + locElem[i + 2] + ":" + locElem[i + 3] + ":" + locElem[i + 4] + ":" + locElem[i + 5]);
                            int         id;
                            if (int.TryParse(locElem[i + 1], out id))
                            {
                                sublocations.Add(id, temp);
                            }
                        }
                    }
                    break;

                case "CurrentSublocation":
                    int currID;
                    if (locElem.Length > 1)
                    {
                        int.TryParse(locElem[1], out currID);
                        sublocations.TryGetValue(currID, out currentSubLocation);
                    }
                    break;
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// Size constructor defaults to constant values for everything except size
        /// Invalid Size (size<=0) is set to STD_SIZE
        /// </summary>
        /// <param name="size">Size of the location (Number of sublocations)</param>
        public void GenerateSubLocations(int size)
        {
            if (size <= 0)
            {
                size = STD_SIZE;
            }
            visited      = false;
            sublocations = new Dictionary <int, Sublocation>();
            var keys = SubLocationFactory.GetRegisteredTypes().ToList();

            for (int i = 1; i < size + 1; i++)
            {
                sublocations.Add(i, GenerateRandomSublocation(i, keys));
            }
            currentSubLocation = null;
        }
Exemple #6
0
        /// <summary>
        /// Generates sub locations based on attibutes given
        /// Invalid params are set to standard values
        /// </summary>
        /// <param name="sizeMin">Minimum size</param>
        /// <param name="sizeMax">Maximum size</param>
        /// <param name="maxItems">Max items to be found at each sublocation</param>
        /// <param name="maxAmount">Max amount of each item to be found at each sublocation</param>
        public void GenerateSubLocations(int sizeMin, int sizeMax, int maxItems, int maxAmount)
        {
            if (sizeMin <= 0)
            {
                sizeMin = 1;
            }
            if (sizeMax <= 0)
            {
                sizeMax = STD_SIZE;
            }
            if (sizeMax < sizeMin)
            {
                sizeMax = sizeMin + 1;
            }
            if (maxItems <= 0)
            {
                maxItems = STD_MAX_ITEMS;
            }
            if (maxAmount <= 0)
            {
                maxAmount = STD_MAX_AMOUNT;
            }
            visited      = false;
            sublocations = new Dictionary <int, Sublocation>();
            var keys = SubLocationFactory.GetRegisteredTypes().ToList();

            int size = rnd.Next(sizeMin, sizeMax + 1);

            for (int i = 1; i < size + 1; i++)
            {
                int sub_maxItems  = rnd.Next(1, maxItems);
                int sub_maxAmount = rnd.Next(1, maxAmount);
                sublocations.Add(i, GenerateRandomSublocation(i, keys, sub_maxItems, sub_maxAmount));
            }
            currentSubLocation = null;
        }
Exemple #7
0
        /// <summary>
        /// Generates sub locations based on attibutes given
        /// Invalid params are set to standard values
        /// </summary>
        /// <param name="size">Size of the location (Number of sublocations)</param>
        /// <param name="maxItems">Max items to be found at each sublocation</param>
        /// <param name="maxAmount">Max amount of each item to be found at each sublocation</param>
        public void GenerateSubLocations(int size, int maxItems, int maxAmount)
        {
            if (size <= 0)
            {
                size = STD_SIZE;
            }
            if (maxItems <= 0)
            {
                maxItems = STD_MAX_ITEMS;
            }
            if (maxAmount <= 0)
            {
                maxAmount = STD_MAX_AMOUNT;
            }
            visited      = false;
            sublocations = new Dictionary <int, Sublocation>();
            var keys = SubLocationFactory.GetRegisteredTypes().ToList();

            for (int i = 1; i < size + 1; i++)
            {
                sublocations.Add(i, GenerateRandomSublocation(i, keys, maxItems, maxAmount));
            }
            currentSubLocation = null;
        }
Exemple #8
0
 /// <summary>
 /// Registers the sublocation with the factory
 /// </summary>
 public static void RegisterSublocation()
 {
     SubLocationFactory.RegisterSubLocation(TYPE, new Civic());
 }
Exemple #9
0
 /// <summary>
 /// Registers the sublocation with the factory
 /// </summary>
 public static void RegisterSublocation()
 {
     SubLocationFactory.RegisterSubLocation(TYPE, new Residential());
 }
Exemple #10
0
        public static bool IsValidLocation(String toTest)
        {
            HashSet <int> tempSubID = new HashSet <int>();
            HashSet <int> tempID    = new HashSet <int>();
            bool          visited;
            int           id = -1;

            String[] lElems = toTest.Split(',');
            if (lElems.Length != 5)
            {
                return(false);
            }
            foreach (String elem in lElems)
            {
                String[] locElem = elem.Split(':');
                switch (locElem[0])
                {
                case "Type":
                    if (locElem.Length != 2 || locElem[1] != TAG)
                    {
                        return(false);
                    }
                    break;

                case "ID":
                    if (locElem.Length != 2 || !int.TryParse(locElem[1], out id) || id < 0)
                    {
                        return(false);
                    }

                    break;

                case "Visited":
                    if (locElem.Length != 2 || !bool.TryParse(locElem[1], out visited))
                    {
                        return(false);
                    }
                    break;

                case "Sublocations":
                    if (locElem.Length > 1)
                    {
                        if (locElem.Length % 6 != 1 || locElem[1] == "")
                        {
                            return(false);
                        }
                        for (int i = 1; i < locElem.Length; i = i + 6)
                        {
                            int         slid;
                            Sublocation type = SubLocationFactory.GetRegisteredSub(locElem[i]);
                            if (type == null || !int.TryParse(locElem[i + 1], out slid) || tempSubID.Contains(slid) || !type.IsValidSublocation(locElem[i] + ":" + locElem[i + 1] + ":" + locElem[i + 2] + ":" + locElem[i + 3] + ":" + locElem[i + 4] + ":" + locElem[i + 5]))
                            {
                                return(false);
                            }
                            tempSubID.Add(slid);
                        }
                    }
                    break;

                case "CurrentSublocation":
                    int currID;
                    if (locElem.Length > 1)
                    {
                        if (locElem.Length != 2 || !int.TryParse(locElem[1], out currID) || currID < 0 || !tempSubID.Contains(currID))
                        {
                            return(false);
                        }
                    }
                    break;

                default:
                    return(false);
                }
            }
            return(true);
        }
Exemple #11
0
 /// <summary>
 /// Parses a sublocation from a string
 /// </summary>
 /// <param name="toParse">The string to parse to a sublocation</param>
 /// <returns>The sublocation parsed</returns>
 private Sublocation ParseSublocationFromString(String toParse)
 {
     return(SubLocationFactory.CreateSubLocation(toParse));
 }
Exemple #12
0
 /// <summary>
 /// Registers the sublocation with the factory
 /// </summary>
 public static void RegisterSublocation()
 {
     SubLocationFactory.RegisterSubLocation(TYPE, new Commercial());
 }