• 大小: 2.96MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-10-15
  • 语言: C#
  • 标签: C#  WinForm  拼图游戏  

资源简介

用C#写的一个支持鼠标拖动拼图的拼图游戏软件。软件能自动对加载的图片进行分割,并打乱顺序后放置在不同的图片框中,用户使用鼠标拖动图片框中的图片进行拼图,还具备挑战计时功能,拼图成功或者挑战失败后,系统会自动进行提示。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Windows.Forms; 

namespace MyAmeazingPuzzle
{
    public static class Cut
    {

        /// 
        /// 获取等比例缩放的图片(高宽不一致时获取最中间部分的图片)
        /// 

        /// 
        /// 
        /// 
        /// 
        public static Image AdjImageToFitSize(this Image fromImage int width int height)
        {
            Bitmap bitmap = new Bitmap(width height);
            Graphics graphics = Graphics.FromImage(bitmap);
            Point point = new Point(0 0);
            Point point2 = new Point(width 0);
            Point point3 = new Point(0 height);
            Point[] destPoints = new Point[] { point point2 point3 };
            Rectangle rect = GetImageRectangle(fromImage);
            graphics.DrawImage(fromImage destPoints rect GraphicsUnit.Pixel);
            Image image = Image.FromHbitmap(bitmap.GetHbitmap());
            bitmap.Dispose();
            graphics.Dispose();
            return image;
        }
        private static Rectangle GetImageRectangle(Image fromImage)
        {//居中位置获取
            int x = 0;
            int y = 0;
            int height = fromImage.Height;
            int width = fromImage.Width;
            if (fromImage.Height > fromImage.Width)
            {
                height = fromImage.Width;
                y = (fromImage.Height - fromImage.Width) / 2;
            }
            else
            {
                width = fromImage.Height;
                x = (fromImage.Width - fromImage.Height) / 2;
            }
            return new Rectangle(x y width height);
        }

        /// 
        /// 将图片切割成小图片图片顺序为先水平后垂直
        /// 

        /// 
        /// 
        /// 
        /// 
        public static Image[] SplitToSmallImages(this Image fromImage int cx int cy)
        {
            Image[] imgs = new Image[cx * cy];
            int nWidth = fromImage.Width / cx;
            int nHeight = fromImage.Height / cy;
            Bitmap image = new Bitmap(nWidth nHeight);
            Graphics graphics = Graphics.FromImage(image);
            for (int i = 0; i < cy; i++)
            {
                for (int j = 0; j < cx; j++)
                {
                    graphics.DrawImage(fromImage 0 0 new Rectangle(j * nWidth i * nHeight nWidth nHeight) GraphicsUnit.Pixel);
                    Image img = Image.FromHbitmap(image.GetHbitmap());
                    int idx = j + i * cx;
                    img.Tag = idx;
                    imgs[idx] = img;
                }
            }
            return imgs;
        }
   

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     70144  2018-01-23 15:07  myPuzzle\myPuzzle\.vs\myPuzzle\v15\.suo

     文件          0  2018-01-03 14:13  myPuzzle\myPuzzle\.vs\myPuzzle\v15\Server\sqlite3\db.lock

     文件     655360  2018-01-23 15:07  myPuzzle\myPuzzle\.vs\myPuzzle\v15\Server\sqlite3\storage.ide

     文件        189  2018-01-03 14:13  myPuzzle\myPuzzle\myPuzzle\App.config

     文件     187795  2017-12-26 21:47  myPuzzle\myPuzzle\myPuzzle\bin\Debug\0.jpg

     文件      24940  2017-12-26 21:22  myPuzzle\myPuzzle\myPuzzle\bin\Debug\1.jpg

     文件      35379  2017-12-26 21:22  myPuzzle\myPuzzle\myPuzzle\bin\Debug\2.jpg

     文件      27807  2017-12-26 21:22  myPuzzle\myPuzzle\myPuzzle\bin\Debug\3.jpg

     文件     207169  2017-12-26 21:23  myPuzzle\myPuzzle\myPuzzle\bin\Debug\4.jpg

     文件     194821  2017-12-26 21:24  myPuzzle\myPuzzle\myPuzzle\bin\Debug\5.jpg

     文件     191475  2017-12-26 21:24  myPuzzle\myPuzzle\myPuzzle\bin\Debug\6.jpg

     文件    1013760  2018-01-23 14:38  myPuzzle\myPuzzle\myPuzzle\bin\Debug\MyAmeazingPuzzle.exe

     文件        189  2018-01-03 14:13  myPuzzle\myPuzzle\myPuzzle\bin\Debug\MyAmeazingPuzzle.exe.config

     文件      42496  2018-01-23 14:38  myPuzzle\myPuzzle\myPuzzle\bin\Debug\MyAmeazingPuzzle.pdb

     文件       1734  2018-01-17 15:10  myPuzzle\myPuzzle\myPuzzle\ClassDiagram1.cd

     文件       3118  2018-01-08 14:09  myPuzzle\myPuzzle\myPuzzle\Cut.cs

     文件      12131  2018-01-08 15:03  myPuzzle\myPuzzle\myPuzzle\Form1.cs

     文件      12498  2018-01-05 21:17  myPuzzle\myPuzzle\myPuzzle\Form1.Designer.cs

     文件     108572  2018-01-05 21:17  myPuzzle\myPuzzle\myPuzzle\Form1.resx

     文件        601  2018-01-08 15:47  myPuzzle\myPuzzle\myPuzzle\Form2.cs

     文件       2594  2018-01-05 21:17  myPuzzle\myPuzzle\myPuzzle\Form2.Designer.cs

     文件     107589  2018-01-05 21:17  myPuzzle\myPuzzle\myPuzzle\Form2.resx

     文件       4492  2018-01-17 16:55  myPuzzle\myPuzzle\myPuzzle\myPuzzle.csproj

     文件       1464  2018-01-04 23:26  myPuzzle\myPuzzle\myPuzzle\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7669  2018-01-22 23:53  myPuzzle\myPuzzle\myPuzzle\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2018-01-07 14:34  myPuzzle\myPuzzle\myPuzzle\obj\Debug\MyAmeazingPuzzle.csproj.CoreCompileInputs.cache

     文件       2356  2018-01-04 23:31  myPuzzle\myPuzzle\myPuzzle\obj\Debug\MyAmeazingPuzzle.csproj.FileListAbsolute.txt

     文件       1315  2018-01-07 13:53  myPuzzle\myPuzzle\myPuzzle\obj\Debug\MyAmeazingPuzzle.csproj.GenerateResource.Cache

     文件       2384  2018-01-03 15:40  myPuzzle\myPuzzle\myPuzzle\obj\Debug\MyAmeazingPuzzle.csprojResolveAssemblyReference.cache

     文件    1013760  2018-01-23 14:38  myPuzzle\myPuzzle\myPuzzle\obj\Debug\MyAmeazingPuzzle.exe

............此处省略37个文件信息

评论

共有 条评论