Ejemplo n.º 1
0
        /// <summary>
        ///Generate and return Random coordinates
        /// </summary>
        /// <param name="GeneratedEvents"></param>
        /// <returns>A random and valid coordinates</returns>
        public static Vector2 Randomcoordinates(List <Event> GeneratedEvents = null)
        {
            Vector2 coordinates;

            //Repeat generating coordinates until it is valid
            do
            {
                double x;
                double y;
                switch (World.CoordinateSystem)
                {
                default:
                case World.coordinateSystem.Integer:
                    //Randomize the x and y value within the world axis range
                    //Adding 1 to the max value are exclusive when convert to int (Unless the random is exactly 1 which is impossible)
                    x = Mathc.RandomRange(World.AxisX.min, World.AxisY.max + 1);
                    y = Mathc.RandomRange(World.AxisY.min, World.AxisY.max + 1);
                    //Create a new coordinates(Vector2)
                    coordinates = new Vector2(Math.Floor(x), Math.Floor(y));
                    break;

                //Randomize the x and y value within the world axis range
                case World.coordinateSystem.Decimal:
                    x = Mathc.RandomRange(World.AxisX);
                    y = Mathc.RandomRange(World.AxisY);
                    //Convert the coordinates into decimal places and create a new coordinates (Vector2)
                    coordinates = new Vector2(Mathc.ConvertToDecimalPlace(x, World.DecimalPlacesForDecimalCoordinateSystem), Mathc.ConvertToDecimalPlace(y, World.DecimalPlacesForDecimalCoordinateSystem));
                    break;
                }
            } while (!validCoordinates(coordinates, GeneratedEvents)); //Check if the coordinates are valid, repeat if invalid

            return(coordinates);
        }