Beispiel #1
0
        private static Figure GenerateRandomFigure(int x, int y)
        {
            int number = RandomNumber.Generate(1, 7);

            try
            {
                switch (number)
                {
                case 1: return(new FigureI(x, y));

                case 2: return(new FigureJ(x, y));

                case 3: return(new FigureL(x, y));

                case 4: return(new FigureO(x, y));

                case 5: return(new FigureS(x, y));

                case 6: return(new FigureT(x, y));

                case 7: return(new FigureZ(x, y));

                default: throw new InvalidFigureException("Figure Number is out of the given range", number);
                }
            }
            catch (InvalidFigureException ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(new FigureI(x, y));
        }
Beispiel #2
0
    public static void Main()
    {
        RandomNumber ex = new RandomNumber();

        Thread.CurrentThread.Name = "Main";
        ex.Generate();
    }
Beispiel #3
0
        private static void RandomNumerTest()
        {
            int num1 = 10;
            int num2 = 50;

            WriteLine($"Random Number Between {num1} and {num2} is {RandomNumber.Generate(num1, num2)}");
        }
Beispiel #4
0
 public static void PlayBoofSound()
 {
     ThreadPool.QueueUserWorkItem(ignoredState =>
     {
         boofSound[RandomNumber.Generate(0, numBoofSounds)].PlaySync();
     });
 }
Beispiel #5
0
        private static double Run(int[] a, int seed, bool threeway, bool builtin)
        {
            RandomNumber.Generate(a, seed);
            var stopwatch = default(Stopwatch);

            if (threeway)
            {
                stopwatch = Stopwatch.StartNew();
                QuicksortThreeway(a, 0, a.Length);
            }
            else if (builtin)
            {
                stopwatch = Stopwatch.StartNew();
                Array.Sort(a);
            }
            else
            {
                stopwatch = Stopwatch.StartNew();
                Quicksort(a, 0, a.Length);
            }
            stopwatch.Stop();
            var elapsed = stopwatch.Elapsed.TotalMilliseconds;

            if (IsSorted(a) == false)
            {
                throw new InvalidOperationException("Not sorted!");
            }
            return(elapsed);
        }
Beispiel #6
0
 private IEnumerator RandomNumbers(int maxAtk, int maxDef)
 {
     for (var i = 0f; i < time; i += randomTime)
     {
         atkNumber.Generate(0, maxAtk + 1);
         defNumber.Generate(0, maxDef + 1);
         yield return(new WaitForSeconds(randomTime));
     }
 }
Beispiel #7
0
        private static int GetNonce()
        {
            var bytes = RandomNumber.Generate(4);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(bytes);
            }

            return(BitConverter.ToInt32(bytes, 0));
        }
Beispiel #8
0
    public static void PlayWooshSound()
    {
        long time = DateTime.Now.Ticks;

        if (time - wooshSoundLastPlayed > wooshSoundConsecutiveDelay)
        {
            wooshSound[RandomNumber.Generate(0, numWooshSounds)].Stop();
            wooshSound[RandomNumber.Generate(0, numWooshSounds)].Play();
            wooshSoundLastPlayed = time;
        }
    }
Beispiel #9
0
    public static void PlayClickSound()
    {
        long time = DateTime.Now.Ticks;

        if (time - clickSoundLastPlayed > clickSoundConsecutiveDelay)
        {
            clickSound[RandomNumber.Generate(0, numClickSounds)].Stop();
            clickSound[RandomNumber.Generate(0, numClickSounds)].Play();
            clickSoundLastPlayed = time;
        }
    }
Beispiel #10
0
    public ActiveBlock(Board board)
    {
        this.board = board;
        int blockType = RandomNumber.Generate(0, Block.numTypes);

        SetType(blockType);
        rotation        = RandomNumber.Generate(0, Block.numRotations);
        x               = (Board.numSquaresX - Width()) / 2;
        y               = 0;
        isNew           = true;
        cannotBeSpawned = !SetLocation(x, y, rotation);
    }
Beispiel #11
0
    public static void PlayGoodSound()
    {
        long time = DateTime.Now.Ticks;

        if (time - goodSoundLastPlayed > goodSoundConsecutiveDelay)
        {
            ThreadPool.QueueUserWorkItem(ignoredState =>
            {
                goodSound[RandomNumber.Generate(0, numGoodSounds)].PlaySync();
            });
            goodSoundLastPlayed = time;
        }
    }
Beispiel #12
0
    private void FixedUpdate()
    {
        // Destroying the current lowest section when it's fully underneath bottomDestructionPoint
        GameObject lastSection       = (GameObject)activeSections[activeSections.Count - 1];
        Bounds     lastSectionBounds = lastSection.GetComponent <Renderer>().bounds;
        float      lastSectionYTop   = lastSection.transform.position.y + (lastSectionBounds.center.y - lastSectionBounds.min.y);

        if (lastSectionYTop <= bottomDestructionPoint)
        {
            activeSections.RemoveAt(activeSections.Count - 1);
            sectionMover.sections = activeSections;
            Destroy(lastSection);
        }

        // Spawning a new section when the current highest section is fully below topSpawningPoint
        GameObject firstSection       = (GameObject)activeSections[0];
        Bounds     firstSectionBounds = firstSection.GetComponent <Renderer>().bounds;
        float      firstSectionYTop   = firstSection.transform.position.y + (firstSectionBounds.center.y - firstSectionBounds.min.y);

        if (firstSectionYTop <= topSpawningPoint)
        {
            GameObject newSection;
            if (sectionTypes.Length == 1)
            {
                newSection = sectionTypes[0];
            }
            else
            {
                int randomSectiontypeIndex = RandomNumber.Generate(0, sectionTypes.Length - 1);
                newSection = sectionTypes[randomSectiontypeIndex];
                sectionTypes[randomSectiontypeIndex]  = sectionTypes[sectionTypes.Length - 1];
                sectionTypes[sectionTypes.Length - 1] = newSection;
            }
            Bounds  newSectionBounds   = newSection.GetComponent <Renderer>().bounds;
            Vector3 newSectionPosition = new Vector3(0, firstSectionYTop + (newSectionBounds.center.y - newSectionBounds.min.y), 0);
            activeSections.Insert(0, Instantiate(newSection, newSectionPosition, new Quaternion(0, 0, 0, 0)));
            sectionMover.sections = activeSections;
        }
    }
Beispiel #13
0
    // Randomly selects a valid section type
    private GameObject selectRandomSectionType()
    {
        // If there's only one section type, skip the random section type selection process and just use the only existing section type
        if (sectionTypes.Length == 1)
        {
            return(sectionTypes[0]);
        }
        else
        {
            /*
             * If no section types have already been randomly selected, any index postion from the sectionTypes array can be the one that's randomly selected.
             * Otherwise, any sectionType index position excluding its last index position can be the one that's randomly selected.
             * After the first randomly selected section type, each time a section type is randomly selected it will be swapped with the section type at the end of the sectionTypes array.
             * This makes randomly selecting a section type that wasn't the previously spawned section type simple to manage.
             * Knowing that the last section type in the selectionTypes array will be the previously used one,
             * we can generate a random index position in the range of 0 to the length of the selectionTypes array minus one,
             * therefore excluding the index position of the previously used section type from being selected.
             */

            int randomSectiontypeIndex;
            if (activeSections.Count == 0)
            {
                randomSectiontypeIndex = RandomNumber.Generate(0, sectionTypes.Length);
            }
            else
            {
                randomSectiontypeIndex = RandomNumber.Generate(0, sectionTypes.Length - 1);
            }

            GameObject newSection = sectionTypes[randomSectiontypeIndex];
            if (randomSectiontypeIndex != sectionTypes.Length - 1)
            {
                sectionTypes[randomSectiontypeIndex]  = sectionTypes[sectionTypes.Length - 1];
                sectionTypes[sectionTypes.Length - 1] = newSection;
            }
            return(newSection);
        }
    }
Beispiel #14
0
 /// <summary>
 /// Represents the abstract class from which all implementations of Hash-based
 /// Message Authentication Code (HMAC) must derive.
 /// </summary>
 /// <param name="hashBitLength">The hash bit length.</param>
 public HMACSHA3(int hashBitLength = 512) : this(RandomNumber.Generate(0x80), hashBitLength)
 {
 }