Exemple #1
0
        private void InitializeParticles(Explosion explosion)
        {
            var lifeTime = RandomNumber.Get(LifetimeRange);

            for (var i = 0; i < explosion.Particles.Length; i++)
            {
                var angleOfVelocity = i / Math.PI * 2;
                var direction       = new Vector2f(
                    (float)Math.Cos(angleOfVelocity),
                    (float)Math.Sin(angleOfVelocity)
                    );

                var variance = RandomNumber.Get(-(int)explosion.Strength, 30);
                var velocity = direction * (explosion.Strength + variance);

                var color = _colorRange[RandomNumber.Get(0, _colorRange.Count)];

                explosion.Particles[i] = new Particle
                {
                    R             = color.R,
                    G             = color.G,
                    B             = color.B,
                    Position      = explosion.Position,
                    Velocity      = velocity,
                    TotalLifetime = lifeTime,
                    Mass          = RandomNumber.GetFloat(.75f, 1.25f)
                };
            }
        }
Exemple #2
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public void SpawnOnEarthSurface()
        {
            var angle = MathUtils.DegreeToRadian(RandomNumber.Get(0, 360));
            var dir   = new Vector2f(
                (float)Math.Cos(angle),
                (float)Math.Sin(angle)
                );
            var position = _game.Earth.Position + dir * (_game.Earth.Radius + 10);

            // Just to make it more interesting.
            var randomAngle = angle + RandomNumber.GetFloat(-1, 1) * Math.PI * .13f;
            var randomDir   = new Vector2f(
                (float)Math.Cos(randomAngle),
                (float)Math.Sin(randomAngle)
                );

            var rocket = new Rocket(RandomNumber.Get(StrengthRange))
            {
                Position      = position,
                Direction     = randomDir,
                Mass          = RandomNumber.Get(MassRange),
                Fuel          = RandomNumber.Get(FuelRange),
                TotalLifetime = RandomNumber.Get(TotalLifeTime)
            };

            _game.AddRocket(rocket);
        }
Exemple #3
0
        public void GetShouldReturnRandomNumberInTheGivenRange()
        {
            var randomNumber = new RandomNumber();

            var result = randomNumber.Get(1, 2);

            Assert.That(result == 1 || result == 2, Is.True);
        }
Exemple #4
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public void Spawn(Vector2f pos)
        {
            var explosion = new Explosion(RandomNumber.Get(DensityRange))
            {
                Strength = RandomNumber.Get(StrengthRange),
                Position = pos
            };

            InitializeParticles(explosion);

            _game.AddExplosion(explosion);
        }
Exemple #5
0
        private bool TryGetSpawnLocation(out Vector2f pos)
        {
            var retryCount = 0;

            do
            {
                pos = _positions[RandomNumber.Get(0, _positions.Count - 1)];
            } while (PointInsideAnyCircle(pos) && ++retryCount < 100_000);

            if (retryCount == 100_000 - 1)
            {
                Console.WriteLine("Unable to spawn more circles... spawning of circles are disabled...");
                return(false);
            }

            return(true);
        }
Exemple #6
0
        public Rock(Panel FooterPanel, Label ScoreLabel, Timer mainTimer, PictureBox CharacterPb,
                    PictureBox HeartPb1, PictureBox HeartPb2, PictureBox HeartPb3, PictureBox HeartPb4, Label RoundLabel, Main main)
        {
            this.FooterPanel = FooterPanel;
            this.ScoreLabel  = ScoreLabel;
            this.mainTimer   = mainTimer;
            this.CharacterPb = CharacterPb;
            this.RoundLabel  = RoundLabel;
            this.HeartPb1    = HeartPb1;
            this.HeartPb2    = HeartPb2;
            this.HeartPb3    = HeartPb3;
            this.HeartPb4    = HeartPb4;

            int locationPos = RandomNumber.Get(0, 1001);

            if (locationPos < 601)
            {
                this.Location = new Point(RandomNumber.Get(50, Client.ClientWidth - 170), 1);
            }
            else
            {
                this.Location = new Point(CharacterPb.Location.X, 1);
            }

            this.SizeMode = PictureBoxSizeMode.StretchImage;

            int chance = RandomNumber.Get(0, 101);

            if (chance != 39 && chance != 31)
            {
                this.Image = Properties.Resources.Rock;
            }
            else if (chance == 39 || chance == 31)
            {
                this.Image = Properties.Resources.heart2;
                this.Name  = "Recover";
            }

            switch (User.Round)
            {
            case 1:
                this.Size = new Size(25, 25);
                break;

            case 2:
                this.Size = new Size(40, 40);
                break;

            case 3:
                this.Size = new Size(55, 55);
                break;

            case 4:
                this.Size = new Size(70, 70);
                break;

            case 5:
                this.Size = new Size(85, 85);
                break;

            case 6:
                this.Size = new Size(100, 100);
                break;

            case 7:
                this.Size = new Size(110, 110);
                break;

            case 8:
                this.Size = new Size(120, 120);
                break;

            case 9:
                this.Size = new Size(130, 130);
                break;

            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
                this.Size = new Size(150, 150);
                break;
            }
            this.objTimer          = new Timer();
            this.objTimer.Interval = Objects.TimerInt;
            this.objTimer.Tick    += ObjTimer_Tick;
            this.objTimer.Start();
        }
Exemple #7
0
 /// <summary>
 /// Generates a Random Number in the Interval Min,Max
 /// </summary>
 /// <param name="min">The minimum.</param>
 /// <param name="max">The maximum.</param>
 /// <returns>System.Int32.</returns>
 internal static int GetRandomNumber(int min, int max)
 {
     return(RandomNumber.Get(min, max));
 }
Exemple #8
0
        public int[,] SudokuMapBuilder()
        {
Start:

            int[,] Map = new int[9, 9];
            int mapCounter = 1;

            List <int[, ]> mapHolder = new List <int[, ]>();

            RandomNumberCorector            randomNumberCorector = new RandomNumberCorector();
            List <NumberCorectorValueTypes> NumberCorectorsList  = new List <NumberCorectorValueTypes>();
            RandomNumber randomNumber = new RandomNumber();
            MapContainer mapContainer = new MapContainer();

            int i              = 0;
            int indexi         = 0;
            int j              = 0;
            int indexj         = 0;
            int indexjComparer = 3;
            int countSquares   = 0;

            int FailFailCount = 0;

            int mapCounter_A = 0;
            int mapCounter_B = 0;

            int  countRow          = 0;
            int  countColumn       = 0;
            bool ifStartsNewSquare = false;

            int failCount   = 0;
            int numberCheck = 0;

            int countMapCounterAtempts = 0;

            RandomHolder = new List <int> {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };

            for (i = indexi; i < Map.GetLength(0); i++)
            {
                countRow++;

                for (j = indexj; j < indexjComparer; j++)
                {
                    countColumn++;

                    if (countColumn > 3)
                    {
                        countColumn = 1;
                    }

                    do
                    {
                        numberCheck = randomNumber.Get(countRow, countColumn, randomNumberCorector, NumberCorectorsList, RandomHolder);


                        if (numberCheck == 666 || randomNumberCorector.TotalImposibleFromHolderList(numberCheck, NumberCorectorsList))
                        {
                            ifStartsNewSquare = true;

                            if (mapCounter > mapHolder.Count)
                            {
                                mapCounter = 1;
                            }

                            failCount++;

                            mapCounter_A = mapCounter;


                            if (mapHolder.Count == 8 && failCount == 1)
                            {
                                FailFailCount++;
                            }

                            if (failCount > 1)
                            {
                                mapCounter++;
                                failCount = 0;
                            }

                            if (FailFailCount == 5)
                            {
                                mapCounter = 5;
                                mapHolder.RemoveRange(mapHolder.Count - 5, 5);
                                FailFailCount = 0;
                            }

                            mapCounter_B = mapCounter;

                            mapContainer.Get(mapHolder, ref Map, mapCounter);

                            RandomHolder = new List <int> {
                                1, 2, 3, 4, 5, 6, 7, 8, 9
                            };

                            if (mapCounter_A != mapCounter_B)
                            {
                                NumberCorectorsList = new List <NumberCorectorValueTypes>();
                            }

                            MapStepBack.SetIndexersToProperPpositions(Map, ref i, ref j, ref indexi, ref indexj, ref indexjComparer, ref countRow, ref countSquares);
                            randomNumberCorector.RemoveSquareNumbers(ref NumberCorectorsList);

                            countColumn = 0;

                            break;
                        }
                        else
                        {
                            Map[i, j] = numberCheck;
                        }
                    } while (NumberChecking.NumberDuplicate(Map, Map[i, j], ref randomNumberCorector, ref NumberCorectorsList, countRow, countColumn, j));


                    if (ifStartsNewSquare == false)
                    {
                        RandomHolder.Remove(Map[i, j]);
                    }

                    ifStartsNewSquare = false;
                }

                if (countRow == 3)
                {
                    countMapCounterAtempts++;
                    NumberCorectorsList = new List <NumberCorectorValueTypes>();

                    CountTry++;
                    if (CountTry > 30)
                    {
                        CountTry = 0;
                        goto Start;
                    }

                    mapContainer.Add(Map, ref mapHolder);
                    mapCounter = 1;

                    countSquares++;
                    if (countSquares == 3 && indexi + 3 < Map.GetLength(0))
                    {
                        countSquares   = 0;
                        indexi        += 3;
                        indexj         = 0;
                        indexjComparer = 3;
                        countRow       = 0;

                        RandomHolder = new List <int> {
                            1, 2, 3, 4, 5, 6, 7, 8, 9
                        };
                    }
                    else
                    {
                        RandomHolder = new List <int> {
                            1, 2, 3, 4, 5, 6, 7, 8, 9
                        };

                        if (i == 5)
                        {
                            i = 2;
                        }
                        else if (i == 8)
                        {
                            i = 5;
                        }
                        else
                        {
                            i = -1;
                        }

                        if (i != 8 && j != 9)
                        {
                            indexjComparer += 3;
                        }
                        else
                        {
                            i = Map.GetLength(0);
                        }

                        indexj += 3;

                        countRow = 0;
                    }
                }
            }
            return(Map);
        }