Esempio n. 1
0
        public List <Dinosaur> GetTeam(RandomizerType type)
        {
            var randomizer = GetRandomizer(type);
            var team       = randomizer?.GetTeam(_dinosaurs);

            return(!team.IsNullOrEmpty() ? team?.OrderByDescending(t => t.Level).ToList() : null);
        }
Esempio n. 2
0
        //Load entry from XML
        //TODO: Add error checking for malformatted XML
        public RandomizerEntry(XmlNode xml)
        {
            this.name = xml.SelectSingleNode("name").InnerText;
            XmlNodeList entriesXml  = xml.SelectSingleNode("vars").ChildNodes;
            XmlNode     requiresXml = xml.SelectSingleNode("requirements");

            this.type = RandomizerEntry.GetTypeFromString(xml.SelectSingleNode("type").InnerText);
            XmlNodeList localesXml = xml.SelectNodes("locales/locale");

            this.entries = new RandomizerVar[entriesXml.Count];
            for (int i = 0; i < entriesXml.Count; i++)
            {
                string value = entriesXml[i].Attributes["value"] == null ? "" : entriesXml[i].Attributes["value"].Value;

                this.entries[i] = new RandomizerVar(entriesXml[i].InnerText, entriesXml[i].Name, value);
            }

            this.reqString = requiresXml.InnerText;

            this.localeNames = new string[localesXml.Count];
            for (int i = 0; i < localesXml.Count; i++)
            {
                this.localeNames[i] = localesXml[i].InnerText;
            }

            GC.Collect();
        }
Esempio n. 3
0
 /// <summary>
 /// Shuffle the input string using the given type
 /// </summary>
 /// <param name="input"> Input string </param>
 /// <param name="type"> Randomizer type </param>
 /// <returns>Shuffled string</returns>
 public string Shuffle(string input, RandomizerType type)
 {
     if (type == RandomizerType.Random)
     {
         return(Shuffle(input, this._random));
     }
     else
     {
         return(Shuffle(input, this._crypto));
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Get the type of randomizer to use
        /// </summary>
        /// <returns>RandomizerEnum -  1- Random and 2 - Crypto </returns>
        private static RandomizerType GetRngType()
        {
            Console.Write("Choose a valid randomizer type (1 - Random, 2 - Crypto) :");

            RandomizerType type = RandomizerType.Random;

            while ((!Enum.TryParse(Console.ReadLine(), out type) && Enum.IsDefined(typeof(RandomizerType), type)))
            {
                Console.WriteLine("The value entered must be either 1 or 2.");
            }

            return(type);
        }
Esempio n. 5
0
        public List <string> GenerateList(RandomizerType randomizerType, int maxListSize)
        {
            if (maxListSize == 0)
            {
                new ArgumentNullException("list size cannot be zero");
            }
            List <string> stringList = new List <string>();

            for (int i = 0; i < maxListSize; i++)
            {
                stringList.Add(Generate(randomizerType));
            }
            return(stringList);
        }
Esempio n. 6
0
        private static bool IsUserReplyValidRandomizer(string question, out RandomizerType type)
        {
            Console.WriteLine(question);
            Console.WriteLine("1 - Standard");
            Console.WriteLine("2 - Weighted");
            Console.WriteLine("3 - Balanced");

            var reply = Console.ReadLine();

            Console.WriteLine();

            type = Utils.GetRandomizerType(reply);
            return(type != RandomizerType.Invalid);
        }
Esempio n. 7
0
        private static IDinosaurRandomizer GetRandomizer(RandomizerType randomizerType)
        {
            switch (randomizerType)
            {
            case RandomizerType.Invalid:
                return(null);

            case RandomizerType.Standard:
                return(new DinosaurRandomizer());

            case RandomizerType.Weighted:
                return(new DinosaurWeightedRandomizer());

            case RandomizerType.Balanced:
                return(new DinosaurBalancedRandomizer());

            default:
                return(null);
            }
        }
Esempio n. 8
0
        public string Generate(RandomizerType randomizerType, int maxSize)
        {
            if (maxSize == 0)
            {
                new ArgumentNullException("size cannot be zero");
            }
            char[] chars = (randomizerType == RandomizerType.Alphabetic ? "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray() : "れづれなるまゝに日暮らし硯にむかひて心にうりゆくよな事を、こはかとなく書きつくればあやうこそものぐるほけれ".ToCharArray());
            byte[] data  = new byte[1];
            using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider())
            {
                crypto.GetNonZeroBytes(data);
                data = new byte[maxSize];
                crypto.GetNonZeroBytes(data);
            }
            StringBuilder result = new StringBuilder(maxSize);

            foreach (byte b in data)
            {
                result.Append(chars[b % (chars.Length)]);
            }
            return(result.ToString());
        }
Esempio n. 9
0
 public string Generate(RandomizerType randomizerType)
 {
     return(Generate(randomizerType, 10));
 }
Esempio n. 10
0
 /// <summary>
 /// Constructs a GameDescriptor for the given gameType
 /// </summary>
 /// <param name="gameType">The Game Type that you would like to construct</param>
 public GameDescriptor(GameType gameType)
 {
     switch (gameType)
     {
         case GameType.FourFours:
             GameType = GameType.FourFours;
             Description =
                 "Four fours is a mathematical puzzle. The goal of four fours is to find the simplest mathematical expression" +
                 " for every whole number from 0 to some maximum, using only common mathematical symbols and the digit four." +
                 " Only the following operations may be used: addition, subtraction, multiplication, division," +
                 " and exponents, modulus, and parentheses.  The original game allowed concatenation of any of the 4's," +
                 " but is not part of this implementation." +
                 " In the case of powers, your must use one or more of the 4s, or operations on the 4s, to form your exponent." +
                 "\r\nWhen an exact solution is not available, the closest solution is found. " +
                 "\r\nThe expression must have exactly four fours. No other digit is allowed. ";
             DealButtonText = "Start Puzzle";
             SolveButtonText = "Solve Next";
             NumberOfOperands = 4;
             useExponents = true;
             useModulus = true;
             findClosest = false;
             RandomizerType = RandomizerType.Fours;
         break;
         case GameType.KryptoCards:
             GameType = GameType.KryptoCards;
             Description =
                 "Krypto Cards is a Mathematical Card Game. Five playing cards are dealt." +
                 " Then, a sixth card is reveiled, and is called the Target Card." +
                 " You must add, subtract, multiply, or divide using each of the playing card numbers" +
                 " to obtain the final solution equal to the Target Card." +
                 " Fractions are not permitted in your calculation." +
                 "\r\nEach card must be used once and only once to obtain Target Card number. ";
             DealButtonText = "Deal Cards";
             SolveButtonText = "Solve Krypto";
             NumberOfOperands = 5;
             useExponents = false;
             useModulus = false;
             findClosest = false;
             RandomizerType = RandomizerType.Card;
         break;
         case GameType.MathDice:
             GameType = GameType.MathDice;
             Description =
                 "Math Dice is a Dice Game. Three 6-Sided playing dice are rolled." +
                 " Then two 12-sided dice are rolled to determine the Target Number." +
                 " You must add, subtract, multiply, divide, or powers using each of the playing dice" +
                 " to obtain the final solution equal to come as close as possible to the Target Number." +
                 " Fractions, decimals, roots, or exponents are not permitted." +
                 " In the case of powers, you must use one or more of the playing dice to get your exponent." +
                 "\r\nAgain, to repeat, when an exact solution is not available, the closest solution is found. " +
                 "\r\nEach playing dice must be used once and only once to obtain the Target Number. ";
             DealButtonText = "Roll Dice";
             SolveButtonText = "Solve Math Dice";
             NumberOfOperands = 3;
             useExponents = false;
             useModulus = false;
             findClosest = true;
             RandomizerType = RandomizerType.Dice;
             break;
     }
 }