public new void CopyTest()
        {
            Random random    = RandomManager.CreateRandom(SeedVariatorType.CallingMethod);
            int    loopCount = 10;
            int    offset    = random.Next(fieldTypes.Length);

            Type[] sourceTypes;

            Type[] targetTypes = GetTestTypes(loopCount, out sourceTypes, offset);

            Xtensive.Tuples.Tuple source         = Xtensive.Tuples.Tuple.Create(sourceTypes);
            Xtensive.Tuples.Tuple target         = Xtensive.Tuples.Tuple.Create(targetTypes);
            Xtensive.Tuples.Tuple sameTypeTarget = Xtensive.Tuples.Tuple.Create(sourceTypes);

            PopulateData(sourceTypes, source);
            PopulateData(targetTypes, target);
            PopulateData(sourceTypes, sameTypeTarget);

            int startingIndex       = random.Next(fieldTypes.Length * loopCount / 3) + fieldTypes.Length;
            int startingTargetIndex = (random.Next(loopCount / 4) + 1) * fieldTypes.Length + offset + startingIndex % fieldTypes.Length;
            int count = random.Next(fieldTypes.Length * loopCount / 4);

            source.CopyTo(target, startingIndex, startingTargetIndex, count);

            AssertAreSame(source, target, startingIndex, startingTargetIndex, count);

            source.CopyTo(sameTypeTarget, source.Count);

            AssertAreSame(source, sameTypeTarget);
        }
Exemplo n.º 2
0
        public void GetBlockTypeTest()
        {
            RandomManager.Stub(rm => rm.Next(9)).Return(4);
            BlockType blockType = TileManager.GetBlockType(TileType.Block);

            Assert.That(BlockType.BlockA4, Is.EqualTo(blockType));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从坐标(x1, y1)滑动到坐标(x2, y2),滑动的路径是随机生成的
        /// </summary>
        /// <param name="x1">滑动的起始坐标的x值</param>
        /// <param name="y1">滑动的起始坐标的y值</param>
        /// <param name="x2">滑动的结束坐标的x值</param>
        /// <param name="y2">滑动的结束坐标的y值</param>
        /// <param name="duration">滑动时长,单位毫秒</param>
        /// <returns>是否成功</returns>
        public bool SwipeRandom(int x1, int y1, int x2, int y2, int duration)
        {
            var patch = new Path();

            patch.MoveTo(x1, y1);

            var n = (y1 - y2) / 10;

            for (var i = 0; i < 10; i++)
            {
                var sx = RandomManager.CreateRandomNumber(1, 30);
                var sy = RandomManager.CreateRandomNumber(1, 30);

                y1 = y1 - sy - n;

                if (y1 > 200)
                {
                    patch.LineTo(x1 + sx, y1);
                }
                else
                {
                    patch.LineTo(x2, y2);
                }
            }

            return(Gestures(null, new GestureDescription.StrokeDescription(patch, 0, duration)));
        }
Exemplo n.º 4
0
    // Generates an Item
    public static Item Create()
    {
        GenerateSprite generateSprite = new GenerateSprite();
        RandomManager  randomManager  = new RandomManager();
        StatFactory    statFactory    = new ConcreteStatFactory();
        Item           asset          = ScriptableObject.CreateInstance <Item>();

        randomManager.SetAnimationCurve();
        asset.itemType     = (Item.ItemType)UnityEngine.Random.Range(0, Enum.GetNames(typeof(Item.ItemType)).Length);
        asset.itemTypeName = asset.itemType.ToString().ToLower();
        asset.rarity       = (Item.Rarity)Mathf.RoundToInt(randomManager.CurveWeightedRandom(randomManager.cumulativeProbability));
        asset.keyword      = (Item.Keywords)Mathf.RoundToInt(randomManager.CurveWeightedRandom(randomManager.cumulativeProbability));
        asset.statCount    = statFactory.GenerateStatAmount(asset.rarity);
        asset.modifierList = new List <Stat>();
        for (int i = 0; i < asset.statCount; i++)
        {
            asset.modifierList.Add(statFactory.GetStat(statFactory.GenerateStatType(), asset));
        }
        asset.itemName             = asset.keyword.ToString().ToLower() + " " + asset.rarity.ToString().ToLower() + " " + asset.itemTypeName;
        asset.itemSpriteList       = generateSprite.GenerateSpriteList(asset.itemType);
        asset.itemSprite           = GenerateSpriteType(asset.itemSpriteList, asset.rarity);
        asset.ItemLevel            = GenerateItemLevel(asset.rarity);
        asset.itemBackgroundSprite = GenerateSpriteType(BackgroundSprites.backgroundSprites, asset.rarity);
        return(asset);
    }
        public void CopyToTest()
        {
            const int iterationCount = 10000000;
            Random    random         = RandomManager.CreateRandom(SeedVariatorType.CallingMethod);

            Xtensive.Tuples.Tuple tuple = Xtensive.Tuples.Tuple.Create(10, 20, 234.456f, 2345.34534d, "aaaaaaaaaaa", DateTime.Now);
            var hashCode = tuple.GetHashCode();
            var copy     = tuple.CreateNew();

            // Warmup
            for (int i = 0; i < iterationCount / 10; i++)
            {
                tuple.CopyTo(copy);
            }

            // Actual run
            TestHelper.CollectGarbage(true);
            // TestLog.Info("Get ready...");
            using (new Measurement("Copying tuples", MeasurementOptions.Log, iterationCount)) {
                for (int i = 0; i < iterationCount; i++)
                {
                    tuple.CopyTo(copy);
                }
            }
        }
        public void EqualsTest()
        {
            const int iterationCount = 10000000;
            Random    random         = RandomManager.CreateRandom(SeedVariatorType.CallingMethod);
            var       tuple          = Xtensive.Tuples.Tuple.Create(10, 20, 234.456f, 2345.34534d, "aaaaaaaaaaa", DateTime.Now);
            var       clone          = tuple.Clone();

            Assert.AreEqual(tuple.GetHashCode(), clone.GetHashCode());
            var equals = AdvancedComparer <Xtensive.Tuples.Tuple> .System.Equals;

            // Warmup
            for (int i = 0; i < iterationCount / 10; i++)
            {
                tuple.Equals(clone);
                equals(tuple, clone);
            }

            // Actual run
            TestHelper.CollectGarbage(true);
            // TestLog.Info("Get ready...");
            using (new Measurement("Comparing using AdvancedComparer tuples", MeasurementOptions.Log, iterationCount))
                for (int i = 0; i < iterationCount; i++)
                {
                    equals(tuple, clone);
                }
            using (new Measurement("Comparing using Equals tuples", MeasurementOptions.Log, iterationCount))
                for (int i = 0; i < iterationCount; i++)
                {
                    tuple.Equals(clone);
                }
        }
Exemplo n.º 7
0
    private void SetColor()
    {
        bool availableTasks       = TaskManager.GetInstance().tasks != null && TaskManager.GetInstance().tasks.Count > 0;
        int  randomChanceForMatch = RandomManager.GetRandomNumber(0, 101);

        if (availableTasks && randomChanceForMatch < PrototypeManager.GetInstance().GetCurrentWave().chanceOfCorrectBodyCombination)
        {
            BodyType taskBodyType = TaskManager.GetInstance().tasks[RandomManager.GetRandomNumber(0, TaskManager.GetInstance().tasks.Count)].Body;
            bodyType = taskBodyType;
        }
        else
        {
            bodyType = (BodyType)Random.Range(0, 3);
        }

        if (bodyType == BodyType.Blue)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.blue;
        }
        else if (bodyType == BodyType.Green)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.green;
        }
        else if (bodyType == BodyType.Red)
        {
            gameObject.GetComponentInChildren <MeshRenderer>().material.color = Color.red;
        }
    }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
        rnd = GameObject.Find("Random").GetComponent <RandomManager>();
        float rad = 2f * Mathf.PI * rnd.NextFloat();

        velocity = new Vector3(_speed * Mathf.Cos(rad), _speed * Mathf.Sin(rad));
    }
Exemplo n.º 9
0
    private void SetColor()
    {
        MeshRenderer[] meshRenderer = GetComponentsInChildren <MeshRenderer>();

        bool availableTasks       = TaskManager.GetInstance().tasks != null && TaskManager.GetInstance().tasks.Count > 0;
        int  randomChanceForMatch = RandomManager.GetRandomNumber(0, 101);

        if (availableTasks && randomChanceForMatch < PrototypeManager.GetInstance().GetCurrentWave().chanceOfCorrectBodyCombination)
        {
            HeadType taskHeadType = TaskManager.GetInstance().tasks[RandomManager.GetRandomNumber(0, TaskManager.GetInstance().tasks.Count)].Head;
            headType = taskHeadType;
        }
        else
        {
            headType = (HeadType)Random.Range(0, 3);
        }

        for (int i = 0; i < meshRenderer.Length; i++)
        {
            if (headType == HeadType.Blue)
            {
                meshRenderer[i].material.color = Color.blue;
            }
            else if (headType == HeadType.Green)
            {
                meshRenderer[i].material.color = Color.green;
            }
            else if (headType == HeadType.Red)
            {
                meshRenderer[i].material.color = Color.red;
            }
        }
    }
Exemplo n.º 10
0
    public override void OnTouch(Entity other)
    {
        base.OnTouch(other);

        if (m_fsm.IsInState <PlayerState_Dead>())
        {
            return;
        }

        ItemInstance ii = other as ItemInstance;

        if (ii != null)
        {
            // Quick hack for Hearth
            if (ii.Item == EItem.Heart)
            {
                // Hard-coded for now
                ReceiveHeal(RandomManager.Next(4, 8));
            }
            else
            {
                Inventory.Carry(ii.Item);
            }

            ii.PickedUp(this);
        }
    }
Exemplo n.º 11
0
    public string verticalDrawName;//立绘图片 TODO后续改成配表
    /// <summary>
    /// TODO通过配表的Setting创建新People(PeopleData后续要改成PeopleSetting)
    /// </summary>
    /// <param name="peopleData"></param>
    public People(PeopleData peopleData)
    {
        this.name   = peopleData.name;
        this.gender = peopleData.gender;
        if (peopleData.name == "毛鹏程")
        {
            isPlayer = true;
        }

        if (gender == Gender.Male)
        {
            int val = RandomManager.Next(1, 4);
            verticalDrawName = "boy" + val;
        }
        else
        {
            int val = RandomManager.Next(1, 8);
            verticalDrawName = "girl" + val;
        }

        PeopleProtoData peopleProtoData = new PeopleProtoData();

        peopleProtoData.Achievement        = new Achievement();
        peopleProtoData.OnlyId             = ConstantVal.SetId;
        peopleProtoData.Name               = peopleData.name;
        peopleProtoData.Gender             = (int)peopleData.gender;
        peopleProtoData.IsPlayer           = isPlayer;
        peopleProtoData.ExamBattleCurLevel = 1;
        CreateNewPropertyData(peopleProtoData);
        RoleManager.Instance.InitPeopleSocializationProperty(peopleProtoData);
        this.protoData = peopleProtoData;
    }
Exemplo n.º 12
0
    /// <summary>
    /// 通过权重得到第几项string数组
    /// </summary>
    /// <returns></returns>
    public static int GetIndexByWeight(List <string> weightList)
    {
        int        totalWeight   = 0;
        List <int> weightIntList = new List <int>();

        for (int i = 0; i < weightList.Count; i++)
        {
            weightIntList.Add(weightList[i].ToInt32());
        }

        for (int i = 0; i < weightIntList.Count; i++)
        {
            totalWeight += weightIntList[i];
        }

        //上下限
        List <int> AList = new List <int>();
        List <int> BList = new List <int>();

        //int ultra = 1000;
        //int val = RandomManager.Next(1, (totalWeight + 1)* ultra);
        //val = 10000;
        //int index = val % totalWeight;

        int index = RandomManager.Next(1, (totalWeight + 1));

        for (int j = 0; j < weightIntList.Count; j++)
        {
            int currWeight = weightIntList[j];
            int A          = 1;
            int B          = 0;
            if (j > 0)
            {
                for (int k = 0; k < j; k++)
                {
                    A = A + weightIntList[k];
                }
            }
            else
            {
                A = 1;
            }
            B = A - 1 + currWeight;
            AList.Add(A);
            BList.Add(B);
        }
        int choosedIndex = 0;

        for (int i = 0; i < AList.Count; i++)
        {
            int theA = AList[i];
            int theB = BList[i];
            if (index >= theA && index <= theB)
            {
                choosedIndex = i;
                break;
            }
        }
        return(choosedIndex);
    }
        /// <summary>
        /// Обновление состояния скрипта.
        /// </summary>
        /// <param name="delta">Время, прошедшее с предыдущего кадра.</param>
        public override void Update(TimeSpan delta)
        {
            int x = (int)Math.Abs(transform.Position.X);

            if (x > pointToMove)
            {
                transform.Position -= speed * (float)delta.TotalSeconds *
                                      Math.Sign(transform.Position.X);
                x = (int)Math.Abs(transform.Position.X);
                if (x < pointToMove)
                {
                    pointToMove = RandomManager.Next(minPosition, maxPosition);
                }
            }
            else
            {
                transform.Position += speed * (float)delta.TotalSeconds *
                                      Math.Sign(transform.Position.X);
                x = (int)Math.Abs(transform.Position.X);
                if (x > pointToMove)
                {
                    pointToMove = RandomManager.Next(minPosition, maxPosition);
                }
            }

            controlledObject.UpdateColliderToTexture();
        }
Exemplo n.º 14
0
    public void InviteCalc()
    {
        //定计划
        for (int i = 0; i < RoleManager.Instance.NPCPeopleList.Count; i++)
        {
            People        me      = RoleManager.Instance.NPCPeopleList[i];
            List <People> tmpList = new List <People>();

            //tmpList.Clear();
            List <ActionSetting> actionSettingList = DataTable._actionList;
            int           actionIndex   = RandomManager.Next(0, actionSettingList.Count);
            ActionSetting actionSetting = actionSettingList[actionIndex];
            me.actionName         = actionSetting.name;
            me.protoData.ActionId = actionSetting.id.ToInt32();
            //邀请0-5人(不能重复邀请
            if (me.protoData.WetalkFriends.Count > 0 && actionSetting.socializationType.ToInt32() != (int)ActionSocializationProperty.MustAlone)
            {
                //暂时一定邀请 这里改成1
                int num = RandomManager.Next(0, me.protoData.WetalkFriends.Count + 1);
                if (num > 0)
                {
                    for (int j = 0; j < num; j++)
                    {
                        People choosed = null;
                        while (choosed == null ||
                               choosed == me ||
                               tmpList.Contains(choosed))
                        {
                            int index = RandomManager.Next(0, me.protoData.WetalkFriends.Count);
                            choosed = RoleManager.Instance.FindPeopleWithOnlyId(me.protoData.WetalkFriends[index]);
                        }
                        tmpList.Add(choosed);
                        if (choosed.isPlayer)
                        {
                            WetalkMsgData wetalkMsgData = new WetalkMsgData(WetalkMsgType.InviteAction,
                                                                            "一起" + actionSetting.name + "吗?", me, choosed, me.protoData.ActionId);
                            SendMsgToPlayer(me, choosed, wetalkMsgData);
                            //SendMsgToPlayer(me, choosed, actionSetting);TODO
                        }
                        me.Invite(choosed);
                        me.Record("邀请" + choosed.protoData.Name + me.actionName);
                        choosed.Record("被" + me.protoData.Name + "邀请" + me.actionName);
                    }
                }
                else
                {
                    me.Record("想今天一个人" + me.actionName);
                }
            }

            else
            {
                //planList.Add(new Plan(me.actionName, me, null));
                me.Record("想今天一个人" + me.actionName);
            }
        }

        //这里如果玩家有被邀请,则发一封信给玩家
    }