Example #1
0
        public void NextEnumInRange()
        {
            var r = new Random();

            for (var i = 0; i < Enum.GetValues(typeof(SomeCode)).Length * 100; i++)
            {
                Assert.That(r.NextEnum(SomeCode.Undefined, SomeCode.Last), Is.InRange(SomeCode.Undefined, SomeCode.Last));
                Assert.That(r.NextEnum(SomeCode.First, SomeCode.Last), Is.InRange(SomeCode.First, SomeCode.Last));
                Assert.That(r.NextEnum(SomeCode.Middle, SomeCode.Middle), Is.EqualTo(SomeCode.Middle));
            }
        }
Example #2
0
        public void Init()
        {
            if (!gameDefinitions.ghostDefinition)
            {
                throw new Exception($"{nameof(GhostDefinition)} doesn't exists!");
            }

            var ghostObjects = GameObject.FindGameObjectsWithTag("Ghost");

            foreach (var ghostObject in ghostObjects)
            {
                var ghostEntity = ecsWorld.NewEntity();
                ghostEntity.Replace(new GhostInFearStateComponent())
                .Replace(new GhostComponent {
                    ghostType = GetGhostType(ghostObject.name),
                    renderer  = ghostObject.GetComponent <MeshRenderer>()
                })
                .Replace(new MovementComponent {
                    desiredPosition = ghostObject.transform.position.ToVector2Int(),
                    heading         = random.NextEnum <Directions>(),
                    speed           = gameDefinitions.ghostDefinition.ghostSpeed,
                })
                .Replace(new WorldObjectCreateRequest {
                    transform = ghostObject.transform
                });
            }
        }
Example #3
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainViewModel()
            : base()
        {
            // データを作成する。
            var r = new Random();

            StaffList = new ObservableCollection<Staff>();

            for (int i = 0; i < MaxStaffCount; i++)
            {
                // ランダムな値をそれぞれ設定する。
                var staff = new Staff()
                {
                    Id   = i,
                    Age  = r.Next(20, 50),
                    Name = NameList[i],
                    Role = r.NextEnum<Role>(Role.All),
                };

                StaffList.Add(staff);
            }

            // 初期値は適当に選択する。
            SelectedStaff = StaffList[r.Next(0, StaffList.Count)];
        }
Example #4
0
        public void NextEnum()
        {
            var r = new Random();

            for (var i = 0; i < Enum.GetValues(typeof(SomeCode)).Length * 100; i++)
            {
                Assert.That(r.NextEnum<SomeCode>(), Is.InRange(SomeCode.Undefined, SomeCode.Last));
            }
        }
Example #5
0
        public void Initialize()
        {
            var ghostConfigBehaviour = Object.FindObjectOfType <GhostConfigBehaviour>();

            if (ghostConfigBehaviour == null)
            {
                throw new Exception("GhostConfigBehaviour must be created!");
            }

            int worldEntity = _world.Entities[0];
            var ghostConfig = _ecsWorld.AddComponent <GhostConfigComponent>(worldEntity);

            ghostConfig.FearStateInSec = ghostConfigBehaviour.FearStateInSec;
            ghostConfig.ScoresPerGhost = ghostConfigBehaviour.ScoresPerGhost;
            ghostConfig.Blinky         = ghostConfigBehaviour.Blinky;
            ghostConfig.Pinky          = ghostConfigBehaviour.Pinky;
            ghostConfig.Inky           = ghostConfigBehaviour.Inky;
            ghostConfig.Clyde          = ghostConfigBehaviour.Clyde;
            ghostConfig.FearState      = ghostConfigBehaviour.FearState;

            GameObject[] ghostObjects = GameObject.FindGameObjectsWithTag("Ghost");
            foreach (GameObject ghostObject in ghostObjects)
            {
                MoveComponent             moveComponent;
                GhostComponent            ghostComponent;
                GhostInFearStateComponent fearState;
                var ghostEntity = _ecsWorld.CreateEntityWith(out ghostComponent, out moveComponent, out fearState);

                switch (ghostObject.name.ToLower())
                {
                case "pinky":
                    ghostComponent.GhostType = GhostTypes.PINKY;
                    break;

                case "inky":
                    ghostComponent.GhostType = GhostTypes.INKY;
                    break;

                case "clyde":
                    ghostComponent.GhostType = GhostTypes.CLYDE;
                    break;

                default:
                    ghostComponent.GhostType = GhostTypes.BLINKY;
                    break;
                }

                moveComponent.DesiredPosition = ghostObject.transform.position.ToVector2Int();
                moveComponent.Heading         = Random.NextEnum <Directions>();
                moveComponent.Speed           = ghostConfigBehaviour.GhostSpeed;

                _ecsWorld.AddComponent <CreateWorldObjectEvent>(ghostEntity).Transform = ghostObject.transform;
            }
        }
Example #6
0
        public void Init()
        {
            if (!_gameDefinitions.ghostDefinition)
            {
                throw new Exception($"{nameof(GhostDefinition)} doesn't exists!");
            }

            GameObject[] ghostObjects = GameObject.FindGameObjectsWithTag("Ghost");
            foreach (GameObject ghostObject in ghostObjects)
            {
                EcsEntity ghostEntity = _ecsWorld.NewEntityWith(
                    out GhostComponent ghostComponent,
                    out MoveComponent moveComponent,
                    out GhostInFearStateComponent _);

                switch (ghostObject.name.ToLower())
                {
                case "pinky":
                    ghostComponent.GhostType = GhostTypes.Pinky;
                    break;

                case "inky":
                    ghostComponent.GhostType = GhostTypes.Inky;
                    break;

                case "clyde":
                    ghostComponent.GhostType = GhostTypes.Clyde;
                    break;

                default:
                    ghostComponent.GhostType = GhostTypes.Blinky;
                    break;
                }

                moveComponent.DesiredPosition = ghostObject.transform.position.ToVector2Int();
                moveComponent.Heading         = _random.NextEnum <Directions>();
                moveComponent.Speed           = _gameDefinitions.ghostDefinition.GhostSpeed;

                ghostComponent.Renderer = ghostObject.GetComponent <MeshRenderer>();
                ghostEntity.Set <CreateWorldObjectEvent>().Transform = ghostObject.transform;
            }
        }
Example #7
0
 /// <summary>
 /// This controls randomly creating a single random symbol from the symbol types, and randomizing it.
 /// </summary>
 /// <param name="generator"></param>
 protected override void OnRandomize(Random generator)
 {
     SymbolType type = generator.NextEnum<SymbolType>();
     _symbols.Clear();
     switch (type)
     {
         case SymbolType.Custom: _symbols.Add(new SimpleSymbol()); break;
         case SymbolType.Character: _symbols.Add(new CharacterSymbol()); break;
         case SymbolType.Picture: _symbols.Add(new CharacterSymbol()); break;
         case SymbolType.Simple: _symbols.Add(new SimpleSymbol()); break;
     }
     // This part will actually randomize the sub-member
     base.OnRandomize(generator);
 }
Example #8
0
        /// <summary>
        /// Occurs during the randomizing process
        /// </summary>
        /// <param name="generator"></param>
        protected override void OnRandomize(Random generator)
        {
            _color = generator.NextColor();
            Opacity = generator.NextFloat();
            _pointShape = generator.NextEnum<PointShape>();

            base.OnRandomize(generator);
        }
Example #9
0
        ///// <summary>
        ///// Adds SimpleStroke copy content
        ///// </summary>
        ///// <param name="copy"></param>
        //protected override void OnCopy(Descriptor copy)
        //{
        //    base.OnCopy(copy);
        //    ISimpleStroke ss = copy as ISimpleStroke;
        //    ss.Color = Color;
        //    ss.Width = Width;
        //    ss.DashStyle = this.DashStyle;
        //}

        /// <summary>
        /// Handles randomization of simple stroke content
        /// </summary>
        /// <param name="generator">The random generator to use for randomizing characteristics.</param>
        protected override void OnRandomize(Random generator)
        {
            _color = generator.NextColor();
            Opacity = generator.NextFloat();
            _width = generator.NextFloat(10);
            _dashStyle = generator.NextEnum<DashStyle>();
            base.OnRandomize(generator);
        }
Example #10
0
 /// <summary>
 /// Extends the randomize code to include the character aspects, creating a random character.
 /// However, since most fonts don't support full unicode values, a character from 0 to 255 is
 /// chosen.
 /// </summary>
 /// <param name="generator">The random class generator</param>
 protected override void OnRandomize(Random generator)
 {
     _color = generator.NextColor();
     Opacity = generator.NextFloat();
     _character = (char)generator.Next(0, 255);
     _fontFamilyName = FontFamily.Families[generator.Next(0, FontFamily.Families.Length - 1)].Name;
     _style = generator.NextEnum<FontStyle>();
     base.OnRandomize(generator);
 }
Example #11
0
 public void NextEnumTest()
 {
     Random rnd = new Random();
     UriKind kind = rnd.NextEnum<UriKind>();
     Assert.IsTrue(new[] { UriKind.Absolute, UriKind.Relative, UriKind.RelativeOrAbsolute }.Contains(kind));
 }
Example #12
0
 /// <summary>
 /// Handles the randomization of the cartographic properties of this stroke.
 /// </summary>
 /// <param name="generator">The random class that generates the random numbers</param>
 protected override void OnRandomize(Random generator)
 {
     base.OnRandomize(generator);
     DashStyle = DashStyle.Custom;
     _dashCap = generator.NextEnum<DashCap>();
     _startCap = generator.NextEnum<LineCap>();
     _endCap = generator.NextEnum<LineCap>();
     _dashButtons = generator.NextBoolArray(1, 20);
     _compoundButtons = generator.NextBoolArray(1, 5);
     _offset = generator.NextFloat(10);
     _joinType = generator.NextEnum<LineJoinType>();
     int len = generator.Next(0, 1);
     if (len > 0)
     {
         _decorations.Clear();
         LineDecoration ld = new LineDecoration();
         ld.Randomize(generator);
         _decorations.Add(ld);
     }
 }
Example #13
0
        public void NextEnumInRangeExceptFails()
        {
            var r = new Random();

            r.NextEnum(SomeCode.Middle, SomeCode.Middle, SomeCode.Middle);
        }
Example #14
0
        public void NextEnumInRangeFails()
        {
            var r = new Random();

            r.NextEnum(SomeCode.Last, SomeCode.First);
        }