コード例 #1
0
 public void ApplyAdjustment()
 {
     if (RandomNumberProvider.Next() < RenewalFactor)
     {
         Weight = RandomNumberProvider.Next();
     }
     Weight += _cumulatedAdjustment;
     _cumulatedAdjustment = 0;
 }
コード例 #2
0
        void OnSwipe(object sender, EventArgs e)
        {
            var args = (GestureHandler.GestureSwipeEventArgs)e;

            Debug.Log("Swipe: " + args.Direction.ToString());
            Debug.Log("Time off beat: " + m_sound.TimeOffBeat());
            if (args.Direction == Defs.Direction.Left)
            {
                audioSource.PlayOneShot(m_settings.LeftSwipeClip);
            }
            else if (args.Direction == Defs.Direction.Right)
            {
                audioSource.PlayOneShot(m_settings.RightSwipeClip);
            }

            if (m_sound.TimeOffBeat() < 0.2f)
            {
                // Valid swipe, test enemy type
                var currentCell = m_dungeon.GetCellAtIndex(m_currentCellIndex);
                if (m_dungeon.HasEnemyAtCell(currentCell))
                {
                    var enemy = m_dungeon.GetEnemyAtCell(currentCell);
                    if (enemy.GetEnemyType() == Enemy.EnemyType.Magic && args.Direction == Defs.Direction.Right ||
                        enemy.GetEnemyType() == Enemy.EnemyType.Melee && args.Direction == Defs.Direction.Left)
                    {
                        // Valid combination, destroy the enemy
                        ++m_avatar.KillCount;
                        enemy.Die();
                        m_dungeon.RemoveEnemyAtCell(currentCell);

                        if (args.Direction == Defs.Direction.Left)
                        {
                            int index = m_rng.Next(m_settings.LeftHitClips.Count);
                            audioSource.PlayOneShot(m_settings.LeftHitClips[index]);
                        }
                        else if (args.Direction == Defs.Direction.Right)
                        {
                            int index = m_rng.Next(m_settings.RightHitClips.Count);
                            audioSource.PlayOneShot(m_settings.RightHitClips[index]);
                        }
                    }
                }
            }
        }
コード例 #3
0
 public void AdjustWeight()
 {
     if (RandomNumberProvider.Next() < RenewalFactor)
     {
         Weight = RandomNumberProvider.Next();
     }
     {
         Weight += GetAdjustment();
     }
 }
コード例 #4
0
        public void TestMethod4()
        {
            var random = new Random();

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(100);
                var inputs = new Random().NextDouble();
                Debug.WriteLine("Random is: " + RandomNumberProvider.Next());
            }
            Debug.WriteLine("End");
        }
コード例 #5
0
        void BuildDungeon()
        {
            // First generate path for the floor and block out all surrounding walls
            Defs.Direction currentDirection = Defs.Direction.Forwards;
            Cell           currentPosition;

            currentPosition.x = 0;
            currentPosition.y = 0;
            AddCellAtPosition(currentPosition.x, currentPosition.y);

            for (int i = 0; i < m_settings.segmentCount; ++i)
            {
                CoordinateOffset offset;
                Defs.Facings.TryGetValue(currentDirection, out offset);

                int length = m_rng.Next(m_settings.minSegmentLength, m_settings.maxSegmentLength);
                for (int j = 0; j < length; ++j)
                {
                    offset.Apply(ref currentPosition);
                    AddCellAtPosition(currentPosition.x, currentPosition.y);
                }

                if (i < m_settings.segmentCount - 1)
                {
                    int directionChange = m_rng.Next(2);
                    if (directionChange == 0)
                    {
                        currentDirection = ChangeDirectionLeft(currentDirection);
                    }
                    else if (directionChange == 1)
                    {
                        currentDirection = ChangeDirectionRight(currentDirection);
                    }
                }
            }

            // Generate floors, tunnelling through the walls with all overlapping cells
            foreach (var entry in m_floorCells)
            {
                CreateFloor(entry);
                m_wallCells.Remove(entry);
            }

            // Generate walls
            foreach (var entry in m_wallCells)
            {
                CreateWall(entry);
            }

            // Find valid locations to spawn enemies
            float       range                = m_settings.maxEnemyPopulation - m_settings.minEnemyPopulation;
            float       enemyPopulation      = m_settings.minEnemyPopulation + System.Convert.ToSingle(m_rng.NextDouble()) * range;
            int         enemiesToSpawn       = System.Convert.ToInt32(m_floorCells.Count * enemyPopulation);
            List <Cell> enemyLocationChoices = new List <Cell>();

            foreach (var cell in m_floorCells)
            {
                enemyLocationChoices.Add(cell);
            }

            // Remove starting tiles from list of location choices
            for (int i = 0; i < 5; ++i)
            {
                var cell = m_dungeon.GetCellAtIndex(i);
                enemyLocationChoices.Remove(cell);
            }

            // Spawn Enemies
            for (int i = 0; i < enemiesToSpawn; ++i)
            {
                int index = m_rng.Next(enemyLocationChoices.Count);
                var type  = (m_rng.Next(2) == 0) ? Enemy.EnemyType.Magic : Enemy.EnemyType.Melee;
                var enemy = m_enemyFactory.CreateEnemy(enemyLocationChoices[index], type);
                enemy.transform.SetParent(transform, false);
                m_dungeon.AddEnemyAtCell(enemyLocationChoices[index], enemy);
                enemyLocationChoices.RemoveAt(index);
            }
        }
コード例 #6
0
 public Link(INeuron start, INeuron end)
 {
     this.start = start;
     this.end   = end;
     Weight     = RandomNumberProvider.Next();
 }