示例#1
0
        /// <summary>
        /// Initializes Location Model
        /// </summary>
        /// <param name="totalLocations">Total number of locations</param>
        public void InitializeLocationModel(int total)
        {
            List <DummyLocation> newLocations = CreateDummyLocations(total);

            foreach (var loc in newLocations)
            {
                unvisitedLocation.Add(loc.GetLocationID(), loc);
            }

            DummyLocation loc0 = new DummyLocation(0);

            unvisitedLocation.Add(0, loc0);
            var wm = new WorldMap(unvisitedLocation.Values);

            worldMap    = wm.tmpBitmap;
            buttonAreas = wm.buttonAreas;
            unvisitedLocation.Remove(0);

            Location startLocation = new Location(0);

            startLocation.GenerateSubLocations(2);
            visitedLocation.Add(0, startLocation);
            currentLocation    = startLocation;
            currentSublocation = null;
        }
示例#2
0
 /// <summary>
 /// Change the current sublocation
 /// </summary>
 /// <param name="subLocationID">The id of the sublocation to change to</param>
 public bool ChangeSubLocation(int subLocationID)
 {
     if (currentLocation.SetCurrentSubLocation(subLocationID))
     {
         currentSublocation = currentLocation.GetCurrentSubLocation();
         return(true);
     }
     return(false);
 }
示例#3
0
        /// <summary>
        /// Constructor for loading a game from save data
        /// </summary>
        /// <param name="visitedLocs">Visisted locations string</param>
        /// <param name="unvisitedLocs">Unvisited locations string</param>
        /// <param name="currLoc">Current location string</param>
        /// <param name="currSLoc">Current sublocation string</param>
        public LocationModel(String visitedLocs, String unvisitedLocs, String currLoc, String currSLoc, String buttonAreas, Bitmap worldMap)
        {
            visitedLocation   = new SortedList <int, Location>();
            unvisitedLocation = new SortedList <int, DummyLocation>();
            this.buttonAreas  = new SortedList <int, System.Windows.Point>();
            this.worldMap     = worldMap;

            String[] visitedElem = visitedLocs.Split('#');
            for (int i = 1; i < visitedElem.Length; i++)
            {
                Location temp = new Location(visitedElem[i]);
                visitedLocation.Add(temp.GetLocationID(), temp);
            }

            String[] unvisitedElem = unvisitedLocs.Split('#');
            for (int j = 1; j < unvisitedElem.Length; j++)
            {
                DummyLocation temp = new DummyLocation(unvisitedElem[j]);
                unvisitedLocation.Add(temp.GetLocationID(), temp);
            }

            String[] areasElem = buttonAreas.Split('#');
            for (int k = 1; k < areasElem.Length; k++)
            {
                String[] kvPair = areasElem[k].Split(':');
                double   xCoord, yCoord;
                int      id;
                if (int.TryParse(kvPair[0], out id) && double.TryParse(kvPair[1], out xCoord) && double.TryParse(kvPair[2], out yCoord))
                {
                    var point = new System.Windows.Point(xCoord, yCoord);
                    this.buttonAreas.Add(id, point);
                }
            }

            int currID;

            if (int.TryParse(currLoc, out currID))
            {
                visitedLocation.TryGetValue(currID, out currentLocation);
            }

            int currSub;

            if (int.TryParse(currSLoc, out currSub))
            {
                if (currSub == 0)
                {
                    currentSublocation = null;
                }
                else
                {
                    currentSublocation = currentLocation.GetSublocationByID(currSub);
                }
            }
        }
示例#4
0
        /// <summary>
        /// Trys to set the current sublocation to the ID passed
        /// </summary>
        /// <param name="sublocationID">ID of the sublocation</param>
        /// <returns>If the sublocation was successfully set or not</returns>
        public bool SetCurrentSubLocation(int sublocationID)
        {
            Sublocation temp;

            if (sublocations.TryGetValue(sublocationID, out temp))
            {
                currentSubLocation = temp;
                return(true);
            }
            return(false);
        }
示例#5
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;
        }
示例#6
0
        /// <summary>
        /// Moves from the current location to a visited location
        /// </summary>
        /// <param name="locationID">ID of the visited location</param>
        /// <returns>If the move was successful</returns>
        private bool MoveToVisitedLocation(int locationID)
        {
            Location toChangeTo;

            if (visitedLocation.TryGetValue(locationID, out toChangeTo))
            {
                currentLocation    = toChangeTo;
                currentSublocation = null;
                return(true);
            }
            return(false);
        }
示例#7
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;
                }
            }
        }
示例#8
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;
        }
示例#9
0
        public LocationModel(String visitedLocs, String unvisitedLocs, String currLoc, String currSLoc)
        {
            visitedLocation   = new SortedList <int, Location>();
            unvisitedLocation = new SortedList <int, DummyLocation>();
            this.buttonAreas  = new SortedList <int, System.Windows.Point>();

            String[] visitedElem = visitedLocs.Split('#');
            for (int i = 1; i < visitedElem.Length; i++)
            {
                Location temp = new Location(visitedElem[i]);
                visitedLocation.Add(temp.GetLocationID(), temp);
            }

            String[] unvisitedElem = unvisitedLocs.Split('#');
            for (int j = 1; j < unvisitedElem.Length; j++)
            {
                DummyLocation temp = new DummyLocation(unvisitedElem[j]);
                unvisitedLocation.Add(temp.GetLocationID(), temp);
            }

            int currID;

            if (int.TryParse(currLoc, out currID))
            {
                visitedLocation.TryGetValue(currID, out currentLocation);
            }

            int currSub;

            if (int.TryParse(currSLoc, out currSub))
            {
                if (currSub == 0)
                {
                    currentSublocation = null;
                }
                else
                {
                    currentSublocation = currentLocation.GetSublocationByID(currSub);
                }
            }
        }
示例#10
0
        /// <summary>
        /// Moves from the current location to an unvisited location
        /// </summary>
        /// <param name="locationID">ID of the unvisited location</param>
        /// <returns>If the move was successful</returns>
        private bool MoveToUnvisitedLocation(int locationID)
        {
            DummyLocation toChangeTo;

            if (unvisitedLocation.TryGetValue(locationID, out toChangeTo))
            {
                Location temp = Location.ConvertToLocation(toChangeTo);

                int minSize   = STD_MIN_SIZE;
                int maxSize   = STD_MAX_SIZE;
                int maxItems  = rnd.Next(1, STD_MAX_ITEMS + 1);
                int maxAmount = rnd.Next(1, STD_MAX_AMOUNT + 1);

                temp.GenerateSubLocations(minSize, maxSize, maxItems, maxAmount);
                temp.SetVisited();
                unvisitedLocation.Remove(locationID);
                visitedLocation.Add(locationID, temp);
                currentLocation    = temp;
                currentSublocation = null;
                return(true);
            }
            return(false);
        }
示例#11
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;
        }
示例#12
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;
        }
示例#13
0
 /// <summary>
 /// Registers a sublocation with the factory
 /// </summary>
 /// <param name="subTypeID">ID of the sublocation type</param>
 /// <param name="subloc">Instance of the sublocation</param>
 public static void RegisterSubLocation(String subTypeID, Sublocation subloc)
 {
     registeredSublocations.Add(subTypeID, subloc);
 }
示例#14
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);
        }
示例#15
0
 public Location(int id) : base(id)
 {
     visited            = true;
     sublocations       = new Dictionary <int, Sublocation>();
     currentSubLocation = null;
 }
示例#16
0
 /// <summary>
 /// Standard Constructor defaults to constant values
 /// </summary>
 public Location() : base()
 {
     visited            = false;
     sublocations       = new Dictionary <int, Sublocation>();
     currentSubLocation = null;
 }