コード例 #1
0
        private void bitmapButtonC1_Click(object sender, EventArgs e)
        {
            int get = MathTool.GetRandom(4) + 2;

            itemGet[level] += get;
            string[] itemNames = { "牛肉", "蜂蜜", "黄油", "水" };
            AddFlowCenter(string.Format("{0}x{1}", itemNames[level], get), "LimeGreen");
            score = GetPoints();
            if (itemGet[level] > itemRequired[level] || score >= 100)
            {
                EndGame();
            }
            else if (itemGet[level] == itemRequired[level])
            {
                for (int i = 1; i < 4; i++)
                {
                    int rlevel = (i + level) % 4;
                    if (itemGet[rlevel] != itemRequired[rlevel])
                    {
                        ChangeFood(rlevel + 1);
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: EquipBook.cs プロジェクト: jayrulez/TOMClassic
        public static int GetRandEquipByLevelQuality(int lv, int qual)
        {
            if (equipLevelDict == null)
            {
                equipLevelDict = new Dictionary <int, List <int> >();
                foreach (var equipConfig in ConfigData.EquipDict.Values)
                {
                    if (equipConfig.Disable)
                    {
                        continue;
                    }
                    int catalog = equipConfig.Level * 10 + equipConfig.Quality;
                    if (!equipLevelDict.ContainsKey(catalog))
                    {
                        equipLevelDict.Add(catalog, new List <int>());
                    }
                    equipLevelDict[catalog].Add(equipConfig.Id);
                }
            }

            int        keyType = lv * 10 + qual;
            List <int> datas;

            if (!equipLevelDict.TryGetValue(keyType, out datas))
            {
                return(0);
            }
            if (datas.Count == 0)
            {
                return(0);
            }
            return(datas[MathTool.GetRandom(datas.Count)]);
        }
        // Assign all points to nearest cluster
        public void UpdatePointsByCentroid() // O(n*k)
        {
            // Clear points in the buckets, they will be re-inserted
            foreach (var bucket in BucketsLookup.Values)
            {
                bucket.Points.Clear();
            }

            foreach (var p in this.points)
            {
                var minDist = Double.MaxValue;
                var index   = string.Empty;
                foreach (var i in BucketsLookup.Keys)
                {
                    var bucket = BucketsLookup[i];
                    if (bucket.IsUsed == false)
                    {
                        continue;
                    }

                    var centroid = bucket.Centroid;
                    var dist     = MathTool.Distance(p, centroid);
                    if (dist < minDist)
                    {
                        // update
                        minDist = dist;
                        index   = i;
                    }
                }
                // re-insert
                var closestBucket = BucketsLookup[index];
                closestBucket.Points.Add(p);
            }
        }
コード例 #4
0
ファイル: ColorWordRegion.cs プロジェクト: realeternia/FEWin
            public void Draw(Graphics g, int tick)
            {
                var img = HSIcons.GetIconsByEName(this.icon);

                switch (danceType)
                {
                case TextDanceTypes.Normal:
                    g.DrawImage(img, x, y, width, width); break;

                case TextDanceTypes.Jump:
                    g.DrawImage(img, x, y + (int)(Math.Sin((double)(tick) / 2) * 5), width, width); break;

                case TextDanceTypes.Shake:
                    g.DrawImage(img, x + (int)(Math.Sin((double)(tick)) * 5), y + (float)(MathTool.GetRandom(0f, 1) * 2), width, width); break;

                case TextDanceTypes.Lovely:
                    g.DrawImage(img, x, y + (int)(Math.Sin(Math.Tan((double)(tick) / 2)) * 3), width, width); break;

                case TextDanceTypes.Random:
                    var rd = MathTool.GetRandom(0, 16); g.DrawImage(img, x + (rd / 4) - 2, y + (rd % 4) - 2, width, width); break;

                case TextDanceTypes.Stripe:
                    g.DrawImage(img, x + (int)(Math.Sin((double)(tick) / 2) * 5), y + (int)(Math.Sin((double)(tick) / 2) * 5), width, width); break;

                case TextDanceTypes.UpDown:
                    g.DrawImage(img, x, y + (int)(Math.Sin((double)(tick) / 3) * 5), width, width); break;

                case TextDanceTypes.UpdownUniform:
                    g.DrawImage(img, x, y + (int)(Math.Sin((double)(tick) / 3) * 5), width, width); break;

                case TextDanceTypes.LeftRightUniform:
                    g.DrawImage(img, x + (int)(Math.Sin((double)(tick) / 3) * 5), y, width, width); break;
                }
            }
コード例 #5
0
        private static int GetSpeed(int type, int danger)
        {
            if (MathTool.GetRandom(100) < breakTable[type - 1, danger])
            {
                return(0);
            }

            int realSpd = 0;

            if (type == SpeedSlow)
            {
                realSpd = MathTool.GetRandom(50, 70);
            }
            else if (type == SpeedMed)
            {
                realSpd = MathTool.GetRandom(90, 110);
            }
            else if (type == SpeedHigh)
            {
                realSpd = MathTool.GetRandom(130, 150);
            }
            else if (type == SpeedSuper)
            {
                realSpd = MathTool.GetRandom(200, 250);
            }
            return(realSpd);
        }
コード例 #6
0
ファイル: Bound.cs プロジェクト: Insane-neal/LocationSystem
        public bool Contains(double x, double y)
        {
            if (MinX == 0 && MaxX == 0)
            {
                SetMinMaxXY();
            }
            if (Shape == 2)//圆形
            {
                var center = GetCenter();
                var sizeX  = GetSizeX();
                var sizeY  = GetSizeY();
                var size   = sizeX > sizeY ? sizeX : sizeY;

                var distance  = (center.X - x) * (center.X - x) + (center.Y - y) * (center.Y - y);
                var distance2 = size * size / 4;
                var r         = distance2 > distance;
                return(r);
            }
            else
            {
                if (Points != null && Points.Count > 4)//不规则多边形
                {
                    return(MathTool.IsInRegion(new Point(x, y, 0, 0), Points.ConvertAll <IVector2>(i => i)));
                }
                return(x >= MinX && x <= MaxX && y >= MinY && y <= MaxY);
            }
        }
コード例 #7
0
        /// <summary>
        /// 返回起始点和结束点中间的所有中间点的坐标
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        private StylusPoint[] getMidPoints(StylusPoint start, StylusPoint end)
        {
            StylusPoint[] results  = { start, end };
            double        distance = MathTool.getInstance().distanceP2P(start, end);

            int numofmidpoints = (int)(distance / DIS_SEP) - 1;

            if (numofmidpoints <= 0)
            {
                return(results);
            }
            StylusPoint[] midpoints = new StylusPoint[numofmidpoints];
            int           offx      = (int)(end.X - start.X);
            int           offy      = (int)(end.Y - start.Y);

            for (int i = 0; i < numofmidpoints; i++)
            {
                midpoints[i]   = new StylusPoint();
                midpoints[i].X = start.X + offx * (i + 1) / (numofmidpoints + 1);
                midpoints[i].Y = start.Y + offy * (i + 1) / (numofmidpoints + 1);
            }
            results    = new StylusPoint[2 + numofmidpoints];
            results[0] = start;
            for (int i = 1; i < numofmidpoints + 1; i++)
            {
                results[i] = midpoints[i - 1];
            }
            results[1 + numofmidpoints] = end;
            return(results);
        }
コード例 #8
0
        private Color SpotDirection(Point hotspot, Color position)
        {
            double px = 3.0 * (double)(position.R) / 255.0 - 1.0;
            double py = 3.0 * (double)(position.G) / 255.0 - 1.0;
            double pz = 3.0 * (double)(position.B) / 255.0 - 1.0;

            double dx = hotspot.X - px;
            double dy = hotspot.Y - py;
            double dz = 0.0 - pz;

            {
                double m = MathTool.Hypot(dx, dy, dz);

                dx = dx / m;
                dy = dy / m;
                dz = dz / m;
            }

            dx = 255.0 * (0.5 + dx * 0.5);
            dy = 255.0 * (0.5 + dy * 0.5);
            dz = 255.0 * (0.5 + dz * 0.5);

            return(new Color()
            {
                R = (byte)Math.Floor(dx), G = (byte)Math.Floor(dy), B = (byte)Math.Floor(dz), A = 255
            });
        }
コード例 #9
0
        private void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;

            if (then != DateTime.MinValue)
            {
                if (Autorun)
                {
                    double z = now.TimeOfDay.TotalSeconds;

                    P0 = new Point(0.5 + MathTool.Noise(0.1, 0.2, z), 0.5 + MathTool.Noise(0.3, 0.4, z));
                    P1 = new Point(0.5 + MathTool.Noise(0.5, 0.6, z), 0.5 + MathTool.Noise(0.7, 0.8, z));
                }
                else
                {
                    double dt = (now - then).TotalSeconds;

                    Point A0 = new Point((hotspot.X - P0.X) * 30, (hotspot.Y - P0.Y) * 30);
                    V0 = new Point(V0.X * 0.9 + A0.X * dt, V0.Y * 0.9 + A0.Y * dt);
                    P0 = new Point(P0.X + V0.X * dt, P0.Y + V0.Y * dt);

                    Point A1 = new Point((hotspot.X - P1.X) * 35, (hotspot.Y - P1.Y) * 35);
                    V1 = new Point(V1.X * 0.7 + A1.X * dt, V1.Y * 0.7 + A1.Y * dt);
                    P1 = new Point(P1.X + V1.X * dt, P1.Y + V1.Y * dt);
                }

                Spot0Direction = SpotDirection(P0, Spot0Position);
                Spot1Direction = SpotDirection(P1, Spot1Position);
            }

            then = now;
        }
コード例 #10
0
        /// <summary>
        /// 获取关键点
        /// </summary>
        /// <param name="intervalLength"></param>
        private void getKeyPoints(int intervalLength)
        {
            StylusPointCollection spc = trackStroke.StylusPoints;
            int firstIndex            = 0;

            keyPoints.Add(spc[firstIndex]);
            double distance = 0;

            for (int i = firstIndex; i < spc.Count - 1; i++)
            {
                double distanc2P = MathTool.getInstance().distanceP2P(spc[i + 1], spc[i]);
                distance += distanc2P;
                int offsetDistance = (int)distance - intervalLength;
                if (offsetDistance > 3)//处理两点间隔距离过大的情况,向中间添加点
                {
                    StylusPoint addPoint = MathTool.getInstance().getPointInLine(spc[i + 1], spc[i], distanc2P - offsetDistance);
                    spc.Add(new StylusPoint(0, 0));
                    for (int j = spc.Count - 2; j > i; j--)
                    {
                        spc[j + 1] = new StylusPoint(spc[j].X, spc[j].Y);
                    }
                    spc[i + 1] = new StylusPoint(addPoint.X, addPoint.Y);
                    //drawPoint(spc[i+1].X, spc[i+1].Y,Colors.Green);
                    keyPoints.Add(spc[i + 1]);
                    distance = 0;
                }
                else if (Math.Abs(offsetDistance) <= 3)
                {
                    //drawPoint(spc[i + 1].X, spc[i + 1].Y, Colors.Blue);
                    keyPoints.Add(spc[i + 1]);
                    distance = 0;
                }
            }
        }
コード例 #11
0
        void IInputPositionListener.OnInputPosition(InputEntity entity, Vector2 worldPos)
        {
            var hittedCharacters = Physics2D.CircleCastAll(worldPos, PushSettings.RaycastRadius, Vector2.zero, 0, CharacterSettings.LayerMask);

            // Если по клику вокруг нет персонажей
            if (hittedCharacters.Length == 0)
            {
                // Добавляем персонажей в месте клика
                for (int i = 0; i < CharacterSettings.CreateCount; i++)
                {
                    var spiralPos = MathTool.GetSpiralPositionByIndex(i);

                    _characterFactory.Create(worldPos + spiralPos * CharacterSettings.Size.MaxValue * 2);
                }
            }
            else
            {
                // Иначе - выталкиваем персонажей
                for (int i = 0; i < hittedCharacters.Length; i++)
                {
                    var hittedCharacter = hittedCharacters[i];

                    var character = (GameEntity)hittedCharacter.collider.gameObject.GetEntityLink().entity;

                    var direction = new Vector2(_randomService.Range(-1f, 1f), 1);
                    var force     = _randomService.Range(PushSettings.Force);

                    character.ReplacePush(direction, force);
                }
            }
        }
コード例 #12
0
ファイル: NormalFixture.cs プロジェクト: 15831944/NFramework
        public void SamplesDistributionTest()
        {
            var source    = Normal.Samples(MathTool.GetRandomFactory()(), 0.0, 1.0).AsParallel().Take(99999).ToList();
            var histogram = new Histogram(source, 50);

            DisplayDistribution("Normal", histogram);
        }
コード例 #13
0
ファイル: CharacterData.cs プロジェクト: HelloWindows/Solider
                } // end Plus

                public void Plus(IEquipInfo info)
                {
                    if (null == info)
                    {
                        return;
                    }
                    // end if
                    XHP  = XHP + info.attributeInfo.XHP;
                    XMP  = XMP + info.attributeInfo.XMP;
                    NATK = NATK + info.attributeInfo.NATK;
                    XATK = XATK + info.attributeInfo.XATK;
                    NMGK = NMGK + info.attributeInfo.NMGK;
                    XMGK = XMGK + info.attributeInfo.XMGK;
                    HOT  = HOT + info.attributeInfo.HOT;
                    MOT  = MOT + info.attributeInfo.MOT;
                    DEF  = DEF + info.attributeInfo.DEF;
                    RGS  = RGS + info.attributeInfo.RGS;
                    if (info.attributeInfo.ASP != 0)
                    {
                        ASP = MathTool.Clamp(ASP * (info.attributeInfo.ASP + 100f) / 100f, 0.2f, 2f);
                    }
                    if (info.attributeInfo.MSP != 0)
                    {
                        MSP = MathTool.Clamp(MSP * (info.attributeInfo.MSP + 100f) / 100f, 0.2f, 5f);
                    }
                    HIT = MathTool.Clamp(HIT + info.attributeInfo.HIT, 0, 100);
                    AVD = MathTool.Clamp(AVD + info.attributeInfo.AVD, 0, 60);
                    CRT = MathTool.Clamp(CRT + info.attributeInfo.CRT, 0, 100);
                } // end Plus
コード例 #14
0
ファイル: CharacterData.cs プロジェクト: HelloWindows/Solider
                } // end  Minus

                public void Plus(IRealData data)
                {
                    if (null == data || false == IsLive || HP == XHP && MP == XMP)
                    {
                        return;
                    }
                    // end if
                    HP = HP + data.HP;
                    MP = MP + data.MP;
                    if (data.HPR > 0)
                    {
                        HP = HP + MathTool.Percent(XHP - HP, data.HPR);
                    }
                    // end if
                    if (data.MPR > 0)
                    {
                        MP = MP + MathTool.Percent(XMP - MP, data.MPR);
                    }
                    // end if
                    if (data.XHR > 0)
                    {
                        HP = HP + MathTool.Percent(XHP, data.XHR);
                    }
                    // end if
                    if (data.XMR > 0)
                    {
                        MP = MP + MathTool.Percent(XMP, data.XMR);
                    }
                    // end if
                    HP = MathTool.Clamp(HP, 0, XHP);
                    MP = MathTool.Clamp(MP, 0, XMP);
                } // end Plus
コード例 #15
0
        public void WeightedMovingAverageNullableLongTest()
        {
            var source    = new long?[] { 1, 2, 3, 6, 7, 9, 11, 8, 10, 11, null, 15, 25 };
            var expected  = new double?[] { 4.4, 6, 7.8, 9.7, 9, 9.5, 10.3, 10.5, 14, 21 };
            var blockSize = 4;

            var actual = MathTool.WeightedMovingAverage(source, blockSize, DoubleWeightGen);

            if (IsDebugEnabled)
            {
                log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString());
            }
            Assert.IsTrue(expected.SequenceEqual(actual));

            //------------------------------//

            try {
                source    = new long?[] { 1, 2, 3, 4, 5 };
                blockSize = 1;
                int x = MathTool.WeightedMovingAverage(source, blockSize).Count();
                Assert.Fail();
            }
            catch (ArgumentException e) {
                Assert.IsTrue(e.ParamName == "blockSize");
            }
            catch (InvalidOperationException) {}
            catch (Exception) {
                Assert.Fail();
            }

            //------------------------------//

            try {
                source    = new long?[] { 1, 2, 3, 4, 5 };
                blockSize = 15;
                int x = MathTool.WeightedMovingAverage(source, blockSize).Count();
                Assert.Fail();
            }
            catch (ArgumentException e) {
                Assert.IsTrue(e.ParamName == "source");
            }
            catch (InvalidOperationException) {}
            catch (Exception) {
                Assert.Fail();
            }

            //------------------------------//

            source    = new long?[] { null, null, null, null, null };
            expected  = new double?[] { null, null };
            blockSize = 4;


            actual = MathTool.WeightedMovingAverage(source, blockSize, DoubleWeightGen);
            if (IsDebugEnabled)
            {
                log.Debug(@"expected=[{0}], actual=[{1}]", expected.CollectionToString(), actual.CollectionToString());
            }
            Assert.IsTrue(expected.SequenceEqual(actual));
        }
コード例 #16
0
    private void ReadInterference(Interference itf)
    {
        double[] k_svt_alpha = { 0,       20.0D,  40.0D,  60.0D,  80.0D, 100.0D, 120.0D,
                                 140.0D, 160.0D, 180.0D, 200.0D, 220.0D, 240.0D, 260.0D, 280.0D,
                                 300.0D, 320.0D, 340.0D, 360.0D };
        double[] k_svt_wg_k_svt = new double[19];
        double[] k_svt_ht_k_svt = new double[19];
        int      i;

        for (i = 0; i < k_svt_alpha.Length; i++)
        {
            k_svt_alpha[i] = MathTool.DegToRad(k_svt_alpha[i]);
        }

        Pass("k_SVtail_Wing_stall(alpha) = ");
        for (i = 0; i < 19; i++)
        {
            k_svt_wg_k_svt[i] = ReadDouble();
        }
        itf.k_SVtail_Wing_stall = new Function2D(k_svt_alpha, k_svt_wg_k_svt);
        Pass("k_SVtail_Htail_stall(alpha) = ");
        for (i = 0; i < 19; i++)
        {
            k_svt_ht_k_svt[i] = ReadDouble();
        }
        itf.k_SVtail_Htail_stall = new Function2D(k_svt_alpha, k_svt_ht_k_svt);
    }
コード例 #17
0
ファイル: TalkEventItemPay.cs プロジェクト: realeternia/FEWin
        private void CalculateRequire()
        {
            int            index = 1;
            List <IntPair> items;

            if (config.PayKey == null || config.PayKey.Length == 0)
            {
                items = ArraysUtils.GetSubArray(UserProfile.InfoBag.GetItemCountByType((int)HItemTypes.Material), 0, 13);
            }
            else
            {
                string pickKey = config.PayKey[MathTool.GetRandom(config.PayKey.Length)];
                items = ArraysUtils.GetSubArray(UserProfile.InfoBag.GetItemCountByAttribute(pickKey), 0, 13);
            }
            for (int i = 0; i < items.Count; i++)
            {
                var region = new ButtonRegion(index, pos.X + 3 + 20 + (index - 1) % 7 * 70, pos.Y + 3 + 25 + (index - 1) / 7 * 70, 60, 60, HItemBook.GetHItemImage(items[i].Type));
                region.SetKeyValue(items[i].Type);
                region.AddDecorator(new RegionTextDecorator(37, 42, 12, Color.White, true, items[i].Value.ToString()));
                vRegion.AddRegion(region);
                index++;
            }

            var button = new ButtonRegion(20, pos.X + 3 + 20 + (index - 1) % 7 * 70, pos.Y + 3 + 25 + (index - 1) / 7 * 70, 60, 60, "iconbg.jpg", "");

            button.AddDecorator(new RegionImageDecorator(HSIcons.GetIconsByEName("rot7"), 60 / 2));
            vRegion.AddRegion(button);
        }
コード例 #18
0
        //打开xml文件
        private void Open_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            
                //打开文件
                OpenFileDialog openfile = new OpenFileDialog()
                {
                    Filter = "Xml Files (*.xml)|*.xml|All Files(*.*)|*.*",
                    Multiselect = false
                };

                if (openfile.ShowDialog() == DialogResult.OK)
                {
					_inkFrame.InkCollector.InkCanvas.Children.Clear();
					_inkFrame.InkCollector.InkCanvas.Strokes.Clear();
					_inkFrame.OperatePieMenu.Visibility = Visibility.Collapsed;
					_inkFrame.InkCollector.Sketch.Images.Clear();
					_inkFrame.InkCollector.Sketch.MyStrokes.Clear();
					_inkFrame.InkCollector.Sketch.MyRichTextBoxs.Clear();
					_inkFrame.InkCollector.Sketch.MyButtons.Clear();
                    MathTool.getInstance().ClearAllStrokesAndChildren(_titleInk.Title_InkFrame);
                    using (Stream stream = openfile.OpenFile())
                    {
                        WPFInk.PersistenceManager.PersistenceManager.getInstance().LoadFromStream(_inkFrame.InkCollector, stream);
                        stream.Close();
                    }
                }
            
        }
コード例 #19
0
        public Histogram(IEnumerable <double> data, int bucketCount)
        {
            data.ShouldNotBeNull("data");
            bucketCount.ShouldBePositive("bucketCount");

            double lower, upper;

            MathTool.GetMinMax(data, out lower, out upper);
            double width = (upper - lower) / bucketCount;

            // Add buckets for each bin; the smallest bucket's lowerbound must be slightly smaller
            // than the minimal element.
            AddBucket(new Bucket(lower.Decrement(), lower + width));
            for (var i = 1; i < bucketCount; i++)
            {
                var lo = lower + i * width;
                AddBucket(new Bucket(lo, lo + width));
            }

            if (IsDebugEnabled)
            {
                log.Debug("Histogram을 생성했습니다. lower=[{0}], upper=[{1}], bucketCount=[{2}]", lower, upper, bucketCount);
            }

            AddData(data);
        }
コード例 #20
0
        public unsafe int LoadAsPOT(ReadOnlySpan <Color4> pixels)
        {
            if (!TextureObject.IsEmpty)
            {
                ThrowAlreadyLoaded();
            }
            // Round up the length at first because it may throw an exception.
            var lengthPowerOfTwo = MathTool.RoundUpToPowerOfTwo(pixels.Length);

            _to     = TextureObject.Create();
            _length = lengthPowerOfTwo;
            TextureObject.Bind1D(_to);
            SetTextureParams();

            // Allocate memory of power of two
            TextureObject.Image1D(lengthPowerOfTwo, (Color4 *)null, TextureInternalFormat.Rgba32f, 0);
            fixed(Color4 *ptr = pixels)
            {
                // Send pixels of actual length
                TextureObject.SubImage1D(0, pixels.Length, ptr, 0);
            }

            TextureObject.Unbind1D();
            return(lengthPowerOfTwo);
        }
コード例 #21
0
        public override void Init(int width, int height)
        {
            base.Init(width, height);
            worldMap = PicLoader.Read("Map", "worldmap.JPG");
            Graphics g = Graphics.FromImage(worldMap);

            foreach (var sceneConfig in ConfigData.SceneDict.Values)
            {
                if (sceneConfig.Icon == "")
                {
                    continue;
                }

                Image image = PicLoader.Read("MapIcon", string.Format("{0}.PNG", sceneConfig.Icon));
                iconSizeDict[sceneConfig.Id] = new Size(image.Width, image.Height);
                Rectangle destRect = new Rectangle(sceneConfig.IconX, sceneConfig.IconY, image.Width, image.Height);
                g.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel,
                            sceneConfig.Level > UserProfile.InfoBasic.Level ? HSImageAttributes.ToRed : HSImageAttributes.ToGray);
                image.Dispose();

                if (sceneConfig.Id == UserProfile.InfoBasic.MapId)
                {
                    baseX = sceneConfig.IconX - 750 / 2 + 30;
                    baseY = sceneConfig.IconY - 500 / 2 + 30;
                    baseX = MathTool.Clamp(baseX, 0, worldMap.Width - 750);
                    baseY = MathTool.Clamp(baseY, 0, worldMap.Height - 500);
                }
            }
            g.Dispose();

            showImage = true;
        }
コード例 #22
0
    /// <summary>
    ///  绘制空心长方形2D
    //   distance指的是这个长方形与Transform t的中心点的距离
    /// </summary>
    /// <param name="t"></param>
    /// <param name="distance"></param>
    /// <param name="length"></param>
    /// <param name="width"></param>
    public static void DrawRectangle2D(Transform t, float distance, float length, float width)
    {
        LineRenderer lr = GetOrAddLineRenderer(t);

        lr.positionCount = 5;

        if (MathTool.IsFacingRight(t))
        {
            Vector2 forwardMiddle = new Vector2(t.position.x + distance, t.position.y);
            lr.SetPosition(0, forwardMiddle + new Vector2(0, width / 2));
            lr.SetPosition(1, forwardMiddle + new Vector2(length, width / 2));
            lr.SetPosition(2, forwardMiddle + new Vector2(length, -width / 2));
            lr.SetPosition(3, forwardMiddle + new Vector2(0, -width / 2));
            lr.SetPosition(4, forwardMiddle + new Vector2(0, width / 2));
        }
        else
        {
            Vector2 forwardMiddle = new Vector2(t.position.x - distance, t.position.y);
            lr.SetPosition(0, forwardMiddle + new Vector2(0, width / 2));
            lr.SetPosition(1, forwardMiddle + new Vector2(-length, width / 2));
            lr.SetPosition(2, forwardMiddle + new Vector2(-length, -width / 2));
            lr.SetPosition(3, forwardMiddle + new Vector2(0, -width / 2));
            lr.SetPosition(4, forwardMiddle + new Vector2(0, width / 2));
        }
    }
コード例 #23
0
        private LiveMonster GetNearestEnemy(bool isLeft, Point mouse)
        {
            LiveMonster target = null;
            int         dis    = int.MaxValue;
            int         rate   = 0;

            foreach (var mon in BattleManager.Instance.MonsterQueue.Enumerator)
            {
                if (mon.IsGhost)
                {
                    continue;
                }

                if (isLeft != mon.Owner.IsLeft)
                {
                    var tpDis = MathTool.GetDistance(mon.Position, mouse);
                    if (tpDis / BattleManager.Instance.MemMap.CardSize * 10 > mon.RealRange &&
                        (isLeft && mon.Position.X < mouse.X || !isLeft && mon.Position.X > mouse.X))    //不管身后的敌人
                    {
                        continue;
                    }

                    var targetRate = GetMonsterRate(mon);
                    if (tpDis < dis || tpDis == dis && targetRate > rate)
                    {
                        dis    = tpDis;
                        target = mon;
                        rate   = targetRate;
                    }
                }
            }
            return(target);
        }
コード例 #24
0
ファイル: ClientGame.cs プロジェクト: karsuszhang/unity_prj
    // Update is called once per frame
    void Update()
    {
        m_InputMng.Update();
        m_Game.Update(MathTool.Second2MilliSec(Time.deltaTime));

        #region update clientobj
        foreach (UnitObject uo in m_ClientObjects)
        {
            uo.Update();
            if (uo.ReleaseInstantly)
            {
                m_DeadObjs.Add(uo);
            }
        }

        foreach (UnitObject du in m_DeadObjs)
        {
            m_ClientObjects.Remove(du);
            du.Release();
        }

        m_DeadObjs.Clear();
        #endregion

        m_DamageObjMng.Update();
    }
コード例 #25
0
        public override void OnFrame(int tick)
        {
            rollItemX += rollItemSpeedX;
            if (rollItemX < 0)
            {
                rollItemX       = 0;
                rollItemSpeedX *= -1;
            }
            if (rollItemX > pos.Width - FrameOff * 2)
            {
                rollItemX       = pos.Width - FrameOff * 2;
                rollItemSpeedX *= -1;
            }

            if (MathTool.GetRandom(10) < 2)
            {
                if (rollItemSpeedX > 0)
                {
                    rollItemSpeedX = rollItemSpeedX - MathTool.GetRandom(1, 3);
                }
                else
                {
                    rollItemSpeedX = rollItemSpeedX + MathTool.GetRandom(1, 3);
                }
                if (Math.Abs(rollItemSpeedX) <= 1)
                {
                    OnStop();
                }
            }
        }
コード例 #26
0
        private void CalculateRequire()
        {
            int index = 1;

            winRate        = config.ChooseWinRate * (10 - hardness) / 10;
            rollItemSpeedX = MathTool.GetRandom(40, 70);

            if (config.ChooseFood > 0)
            {
                int foodCost = (int)GameResourceBook.OutFoodSceneQuest(config.ChooseFood, true);
                var region   = ComplexRegion.GetResButtonRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25 + 70), 60, ImageRegionCellType.Food, -foodCost);
                region.Parm = ImageRegionCellType.Food;
                vRegion.AddRegion(region);
                index++;
            }

            if (config.ChooseGold > 0)
            {
                int goldCost = (int)GameResourceBook.OutGoldSceneQuest(level, config.ChooseGold, true);
                var region   = ComplexRegion.GetResButtonRegion(index, new Point(pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25 + 70), 60, ImageRegionCellType.Gold, -goldCost);
                region.Parm = ImageRegionCellType.Gold;
                vRegion.AddRegion(region);
                index++;
            }

            var button = new ButtonRegion(20, pos.X + 3 + 20 + (index - 1) * 70, pos.Y + 3 + 25 + 70, 60, 60, "iconbg.jpg", "");

            button.AddDecorator(new RegionImageDecorator(HSIcons.GetIconsByEName("rot7"), 60 / 2));
            vRegion.AddRegion(button);
        }
コード例 #27
0
        static void TestFloor()
        {
            const int delta = 10;
            //CW(((int)(179 / delta)) * delta);
            //CW(((int)(-179 / delta)) * delta);

            double a = -185;
            double b = 175;
            //CW(a.NormalizeLongitude() );
            //CW(b.NormalizeLongitude() );

            var v = MathTool.FloorLatLon(a, delta) - delta;

            CW(v);
            var w = MathTool.FloorLatLon(b, delta) - delta;

            CW(w);

            //var v = MathTool.FloorLatLon(a, delta);
            //CW(v);
            //var w = MathTool.FloorLatLon(b, delta);
            //CW(w);

            CW(v.NormalizeLongitude());
            CW(w.NormalizeLongitude());
        }
コード例 #28
0
        public void CheckAllTournament(int day)
        {
            foreach (var tournamentConfig in ConfigData.TournamentDict.Values)
            {
                if (tournamentConfig.ApplyDate == day)
                {
                    DbTournamentData tourdata = GetTournamentData(tournamentConfig.Id);
                    tourdata.Pids = PeopleBook.GetRandNPeople(tournamentConfig.PlayerCount, tournamentConfig.MinLevel, tournamentConfig.MaxLevel);
                    if (tourdata.Engage)
                    {
                        tourdata.Pids[MathTool.GetRandom(tournamentConfig.PlayerCount)] = -1; //player
                    }
                    tourdata.Results = new MatchResult[tournamentConfig.MaxLevel];
                }

                if (tournamentConfig.BeginDate <= day && tournamentConfig.EndDate >= day)
                {
                    foreach (int mid in TournamentBook.GetTournamentMatchIds(tournamentConfig.Id))
                    {
                        TournamentMatchConfig tournamentMatchConfig = ConfigData.GetTournamentMatchConfig(mid);
                        if (tournamentMatchConfig.Date == day && Tournaments[tournamentConfig.Id].Results[tournamentMatchConfig.Offset].Winner == 0)
                        {
                            Tournaments[tournamentConfig.Id].CheckMatch(tournamentMatchConfig.Offset, true);
                        }
                    }
                }
                if (tournamentConfig.EndDate == day)
                {
                    Tournaments[tournamentConfig.Id].Award();
                }
            }
        }
コード例 #29
0
        public void InstanceCachingTest()
        {
            // This is only for test code.
            // 'listCore' is actually on the heap memory.
            var listCore = new ArrayPooledListCore <string>();

            Assert.True(listCore.Count == 0);
            Assert.True(listCore.Capacity == 0);

            listCore.Add(0.ToString());
            var innerArray = Unsafe.As <ArrayPooledListCore <string>, Dummy <string> >(ref listCore).Array;

            for (int i = 1; i < 10; i++)
            {
                listCore.Add(i.ToString());
                Assert.True(listCore.Count == i + 1);
                Assert.True(MathTool.IsPowerOfTwo(listCore.Capacity));
            }

            // Create new listCore
            var listCore2 = new ArrayPooledListCore <string>();

            listCore2.Add("a");
            var innerArray2 = Unsafe.As <ArrayPooledListCore <string>, Dummy <string> >(ref listCore2).Array;

            // Inner array is cached in the pool.
            Assert.True(innerArray == innerArray2);
        }
コード例 #30
0
        private int GetSelectedCell(int x, int y)
        {
            int newsel = -1;

            for (int i = 0; i < 9; i++)
            {
                int baseX = 15 + 218;
                int baseY = 40 + 56;
                if ((i / 3) != 0)
                {
                    baseX += 70 * (i / 3);
                    baseY += 40 * (i / 3);
                }
                if ((i % 3) != 0)
                {
                    baseX -= 80 * (i % 3);
                    baseY += 40 * (i % 3);
                }
                baseX = x - baseX;
                baseY = y - baseY;
                if (MathTool.ValueBetween(baseY, baseX / 2 - 41, baseX / 2 + 44) && MathTool.ValueBetween(baseY, -baseX / 2 + 44, -baseX / 2 + 127))
                {
                    newsel = i;
                }
            }
            return(newsel);
        }