Esempio n. 1
0
        public int RandomHP(StaticTypes type, bool big, bool medium, bool small)
        {
            int min = 0;
            int max = 0;

            switch (type)
            {
            case StaticTypes.tree:
                if (big)
                {
                    max = Constants.bTreeHP;
                    min = Constants.bTreeHP - Constants.treeDiff;
                }
                if (medium)
                {
                    if (!big)
                    {
                        max = Constants.mTreeHP;
                    }
                    min = Constants.mTreeHP - Constants.treeDiff;
                }
                if (small)
                {
                    if (!big && !medium)
                    {
                        max = Constants.sTreeHP;
                    }
                    min = Constants.sTreeHP - Constants.treeDiff;
                }
                break;

            case StaticTypes.rock:
                if (big)
                {
                    max = Constants.bRockHP;
                    min = Constants.bRockHP - Constants.rockDiff;
                }
                if (medium)
                {
                    if (!big)
                    {
                        max = Constants.mRockHP;
                    }
                    min = Constants.mRockHP - Constants.rockDiff;
                }
                if (small)
                {
                    if (!big && !medium)
                    {
                        max = Constants.sRockHP;
                    }
                    min = Constants.sRockHP - Constants.rockDiff;
                }
                break;
            }
            return(rnd.Next(min, max));
        }
Esempio n. 2
0
        protected float[] SetRotation(StaticTypes type, float[] rot)
        {
            switch (type)
            {
            case StaticTypes.tree:
                return(new float[] { 0, rot[1], 0, 1 });

            case StaticTypes.rock:
                return(new float[] { rot[0], rot[1], rot[2], 1 });

            default:
                return(rot);
            }
        }
Esempio n. 3
0
        public static bool CheckIpIsValid(string userIp, StaticTypes type)
        {
            // Reg ex for IP not Subnets
            var regex = new Regex(@"^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\.([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$");

            if (type == StaticTypes.Subnet)
            {
                regex = new Regex(@"^(((255\.){3}(255|254|252|248|240|224|192|128|0+))|((255\.){2}(255|254|252|248|240|224|192|128|0+)\.0)|((255\.)(255|254|252|248|240|224|192|128|0+)(\.0+){2})|((255|254|252|248|240|224|192|128|0+)(\.0+){3}))$");
            }
            // First check
            if (regex.IsMatch(userIp))
            {
                // Second check
                return(IPAddress.TryParse(userIp, out _));
            }
            // Error state
            return(false);
        }
Esempio n. 4
0
        public int[] Add(StaticTypes staticType, ObjectType type, BaseGameRoom room, int count, bool big, bool medium, bool small)
        {
            int number = Offset + count;

            int[] ranges = new int[] { Offset, number - 1 };
            ChangeLength(number);
            _ranges.Add(staticType, ranges);
            while (Offset < number)
            {
                _list[Offset] = new StaticObject(Offset,
                                                 staticType,
                                                 type,
                                                 room.randomer.RandomHP(staticType, big, medium, small),
                                                 room.randomer.RandomPosition(type),
                                                 room.randomer.RandomRotation());
                Offset++;
            }
            return(ranges);
        }
Esempio n. 5
0
        /// <summary>
        /// A method to get a valid ip from the user.
        /// </summary>
        /// <param name="type"> This is for the user messsage, if you want the user to enter in Gateway type should be "Gateway"</param>
        /// <returns>The IP address from the user.</returns>
        public static string GetIp(StaticTypes type)
        {
            // Onlt true if the IP address is valid.
            bool userSelectionValid;
            // the IP the user enters and will be returned if correct.
            string userIp = string.Empty;

            do
            {
                // We ask the user for input
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine(Environment.NewLine + type + Environment.NewLine);
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine($"Enter in an address, select from this list");
                if (type != StaticTypes.IP)
                {
                    Console.WriteLine("or press enter to skip:");
                }
                // We write to console a list of AppSettings with a 0-99 for user section.
                Predefined.OutputList();
                Console.WriteLine();
                // Get user input...
                var userInput = Console.ReadLine();
                // Only for Subnet, Gateway or DNS...
                if (string.IsNullOrWhiteSpace(userInput) && type != StaticTypes.IP)
                {
                    switch (type)
                    {
                    case StaticTypes.Subnet:
                        userIp = "255.255.255.0";
                        break;

                    case StaticTypes.Gateway:
                        userIp = "192.168.0.1";
                        break;

                    case StaticTypes.DNS:
                        userIp = "192.168.0.1";
                        break;
                    }
                }
                // We can only accept 0 - 99, otherwise it'll be a full IP address (e.g. 192.168.0.1)
                else if (userInput.Length < 2)
                // We get it from the list
                {
                    userIp = Predefined.GetPredefinedOrEmpty(userInput);
                }
                // Otherwise it isn't a predefined ip so we use the user's entered data
                else
                {
                    userIp = userInput;
                }
                // We check if it is valid and return if it is.
                userSelectionValid = IP.CheckIpIsValid(userIp, type);
                if (!userSelectionValid)
                {
                    // The user entered in something wrong, we will reset and try again.
                    Log.LogMessageError($"Sorry you entered: {userIp} and this is not a valid for {type}. Try again.");
                }
                // The user made a right entry or selected from the list.
            } while (!userSelectionValid);
            // We tell the use rhwat they selected and move on.
            Log.LogMessage($"{type} has been set as: {userIp}");
            return(userIp);
        }
Esempio n. 6
0
 public bool GetRange(StaticTypes type, out int[] ranges)
 {
     return(_ranges.TryGetValue(type, out ranges));
 }
Esempio n. 7
0
 /// <summary>
 /// Add
 /// </summary>
 /// <param name="type">Type</param>
 /// <param name="positionMatrix">Position matrix</param>
 public static void Add(StaticTypes type, Matrix positionMatrix)
 {
     staticObjects.Add(new StaticGameObject(type, positionMatrix));
 }
Esempio n. 8
0
 public StaticObject(int index, StaticTypes staticType, ObjectType type, int hp, float[] position, float[] rotation) : base(index, type, hp, position, rotation)
 {
     currHP          = hp;
     this.staticType = staticType;
     this.rotation   = SetRotation(staticType, rotation);
 }