コード例 #1
0
ファイル: BoxItem.cs プロジェクト: ztinybing/PushBox
        public string GetImgName(DirectionOptions dir, int index)
        {
            List <string> imageList = null;

            switch (dir)
            {
            case DirectionOptions.Up:
                imageList = this.UpImageList;
                break;

            case DirectionOptions.Down:
                imageList = this.DownImageList;
                break;

            case DirectionOptions.Left:
                imageList = this.LeftImageList;
                break;

            case DirectionOptions.Right:
                imageList = this.RightImageList;
                break;

            default: return(this.DefaultImg);
            }
            //该方向图片数量为0,则显示默认图片
            if (imageList.Count <= 0)
            {
                return(this.DefaultImg);
            }
            return(imageList[index % imageList.Count]);
        }
コード例 #2
0
        /// <summary>
        /// 根据基点获取指定方向上的邻接点
        /// </summary>
        /// <param name="basePoint">基点</param>
        /// <param name="dir">指定方向</param>
        /// <returns>指定方向上的邻接点</returns>
        private Point GetPointByDir(Point basePoint, DirectionOptions dir)
        {
            switch (dir)
            {
            case DirectionOptions.Up: return(new Point(basePoint.X, basePoint.Y - 1));

            case DirectionOptions.Down: return(new Point(basePoint.X, basePoint.Y + 1));

            case DirectionOptions.Left: return(new Point(basePoint.X - 1, basePoint.Y));

            case DirectionOptions.Right: return(new Point(basePoint.X + 1, basePoint.Y));
            }
            return(basePoint);
        }
コード例 #3
0
        /// <summary>
        /// 向指定方向移动
        /// </summary>
        /// <param name="dirOpt">指定方向</param>
        /// <returns>是否移动成功</returns>
        private bool Move(DirectionOptions dirOpt)
        {
            this.characterDirection  = dirOpt;
            this.CharacterTimerCount = 0;
            uint roleLayer = (uint)LayerOptions.Role;

            if (!this.LayerMapDict.ContainsKey(roleLayer))
            {
                return(false);
            }
            List <KeyValuePair <Point, BoxItem> > rolePairList = new List <KeyValuePair <Point, BoxItem> >();

            foreach (KeyValuePair <Point, BoxItem> pair in this.LayerMapDict[roleLayer])
            {
                rolePairList.Add(pair);
            }
            foreach (KeyValuePair <Point, BoxItem> pair in rolePairList)
            {
                this.LayerMapDict[roleLayer].Remove(pair.Key);
            }
            bool moved = false;//是否移动成功

            foreach (KeyValuePair <Point, BoxItem> pair in rolePairList)
            {
                bool canMove = CanMoveTo(pair.Key, dirOpt, true);
                if (!moved && canMove)
                {
                    moved = true;
                }
                if (!canMove)
                {
                    this.LayerMapDict[roleLayer][pair.Key] = pair.Value;
                    continue;
                }
                Point neighborPoint = GetPointByDir(pair.Key, dirOpt);
                this.LayerMapDict[roleLayer][neighborPoint] = pair.Value;
                foreach (KeyValuePair <uint, BoxItem> layerMapPair in this.GetBoxItemsByPoint(neighborPoint))
                {
                    if (layerMapPair.Key == (uint)LayerOptions.Box)
                    {
                        layerMapDict[layerMapPair.Key].Remove(neighborPoint);
                        layerMapDict[layerMapPair.Key][GetPointByDir(neighborPoint, dirOpt)] = layerMapPair.Value;
                    }
                }
            }

            return(moved);
        }
コード例 #4
0
        /// <summary>
        /// 是否能向指定方向移动
        /// </summary>
        /// <param name="basePoint">当前点</param>
        /// <param name="dirOpt">指定方向</param>
        /// <param name="isRole">当前点是否是角色</param>
        /// <returns>是否能移动</returns>
        private bool CanMoveTo(Point basePoint, DirectionOptions dirOpt, bool isRole)
        {
            Point neighborPoint = GetPointByDir(basePoint, dirOpt);
            bool  canMove       = true;

            foreach (KeyValuePair <uint, BoxItem> layerBoxPair in GetBoxItemsByPoint(neighborPoint))
            {
                //角色点移动方向是箱子,则再判断箱子能否向该方向移动
                if (isRole && layerBoxPair.Key == (uint)LayerOptions.Box)
                {
                    canMove &= CanMoveTo(neighborPoint, dirOpt, false);
                    continue;
                }
                canMove &= layerBoxPair.Value.CanCross;
            }
            return(canMove);
        }
コード例 #5
0
 void timer_Tick(object sender, EventArgs e)
 {
     //转换方向
     if (curDirectionCount >= turnDirectionCount)
     {
         curDir            = RndDirection.NewRndDirection;
         curDirectionCount = 0;
     }
     //方向图片显示
     foreach (Control c in pcPrefab.Controls)
     {
         PrefabItemUI prefabItemUI = c as PrefabItemUI;
         if (prefabItemUI == null)
         {
             continue;
         }
         prefabItemUI.ShowDirection = curDir;
         prefabItemUI.ShowIndex     = directCountDict[curDir];
     }
     //当前方向计次增加
     directCountDict[curDir]++;
     curDirectionCount++;
 }
コード例 #6
0
        public static Bitmap AddTextToImage(Bitmap bitmap, string text, int opacity, DirectionOptions directionOptions, Font textFont, bool automatic, Color textColor, Color textBackColor, HatchStyle brushStyle)
        {
            var pointTo  = new Point();
            var textSize = new Size();

            _brush = new HatchBrush(brushStyle, textColor, textBackColor);
            var imageFrom    = new Bitmap(10, 10);
            var downGraphics = Graphics.FromImage(imageFrom);

            textSize.Width  = (int)downGraphics.MeasureString(text, textFont).Width;
            textSize.Height = (int)downGraphics.MeasureString(text, textFont).Height;
            _font           = new Font(textFont.FontFamily, textFont.Size);
            if ((textSize.Width > bitmap.Width || textSize.Height > bitmap.Height) && automatic)
            {
                for (var i = 0; i < 101; i++)
                {
                    _font           = new Font(textFont.FontFamily, textFont.Size * ((float)(100 - i) / 100));
                    textSize.Width  = (int)downGraphics.MeasureString(text, _font).Width;
                    textSize.Height = (int)downGraphics.MeasureString(text, _font).Height;
                    if (textSize.Width <= bitmap.Width && textSize.Height <= bitmap.Height)
                    {
                        break;
                    }
                }
            }
            imageFrom    = new Bitmap(textSize.Width, textSize.Height);
            downGraphics = Graphics.FromImage(imageFrom);
            downGraphics.DrawString(text, _font, _brush, new Point(0, 0));
            var opacityValue = opacity / 10.0F;

            float[][] matrix         = { new float[] { 1, 0, 0, 0, 0 }, new float[] { 0, 1, 0, 0, 0 }, new float[] { 0, 0, 1, 0, 0 }, new[] { 0, 0, 0, opacityValue, 1 }, new float[] { 0, 0, 0, 0, 1 } };
            var       colorMatrix    = new ColorMatrix(matrix);
            var       imageAttribute = new ImageAttributes();

            imageAttribute.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            if (text == "")
            {
                throw new NullReferenceException("Resmin üstüne konacak yazı girilmemiş.");
            }
            if (bitmap == null)
            {
                throw new NullReferenceException("Üzerine yazı yazılacak resim belirlenmedi.");
            }
            if (directionOptions == 0)
            {
                throw new NullReferenceException("Yazının resmin neresine yerleştirileceği belirlenmedi.");
            }
            var graphicsFromImage = Graphics.FromImage(bitmap);

            graphicsFromImage.InterpolationMode = InterpolationMode.High;
            switch (directionOptions)
            {
            case DirectionOptions.TopRight:
                pointTo.X = bitmap.Width - imageFrom.Width;
                pointTo.Y = 0;
                break;

            case DirectionOptions.BottomLeft:
                pointTo.X = 0;
                pointTo.Y = bitmap.Height - imageFrom.Height;
                break;

            case DirectionOptions.TopLeft:
                pointTo.X = 0;
                pointTo.Y = 0;

                break;

            case DirectionOptions.BottomRight:
                pointTo.X = bitmap.Width - imageFrom.Width;
                pointTo.Y = bitmap.Height - imageFrom.Height;

                break;

            case DirectionOptions.MiddleRight:
                pointTo.X = bitmap.Width - imageFrom.Width;
                pointTo.Y = bitmap.Height - (imageFrom.Height - (imageFrom.Height / 2));

                break;

            case DirectionOptions.MiddleLeft:
                pointTo.X = 0;
                pointTo.Y = bitmap.Height - (imageFrom.Height - (imageFrom.Height / 2));

                break;

            case DirectionOptions.TopCenter:
                pointTo.X = bitmap.Width - (imageFrom.Width - (imageFrom.Width / 2));
                pointTo.Y = 0;

                break;

            case DirectionOptions.BottomCenter:
                pointTo.X = bitmap.Width - (imageFrom.Width - (imageFrom.Width / 2));
                pointTo.Y = bitmap.Height - imageFrom.Height;

                break;

            case DirectionOptions.Center:
                pointTo.X = (bitmap.Width / 2) - (imageFrom.Width / 2);
                pointTo.Y = (bitmap.Height / 2) - (imageFrom.Height / 2);

                break;

            default:
                pointTo.X = 0;
                pointTo.Y = 0;

                break;
            }
            graphicsFromImage.DrawImage(imageFrom, new Rectangle(pointTo, imageFrom.Size), 0, 0, imageFrom.Width, imageFrom.Height, GraphicsUnit.Pixel, imageAttribute);
            return(bitmap);
        }