C#拼图游戏

本文介绍了一个使用C#开发的WinForm拼图游戏。首先讲述了创建窗体应用程序的步骤,接着讨论了如何动态加载图片,利用Bitmap对象处理图像。然后,介绍了图块类的设计,包括鼠标交互效果和图块位置的判断。最后,详细阐述了如何创建图块数组,分割图片以及打乱图块的实现方法。
摘要由CSDN通过智能技术生成

    大家好,这次我要为大家带来的是一个用C#写的WinForm游戏,名字叫做拼图游戏。拼图游戏想必大家肯定玩过,玩法我就不赘述了。

首先向大家展示一下运行效果图吧:

 

 

 

    1:写一个WinForm游戏首先要干嘛呢?

   当能是打开vs2010,创建一个Window应用程序了。那么我们就创建一个应用程序,并命名为: LilacFlower。对于一个窗体应用程序,vs2010在图形界面对控件的布局以及属性事件的设置可以说是当今世界上最好的软件了。那么我们从工具箱里面拖动控件放到窗体界面上,效果图如下:

具体参照Form1.Designer.cs文件:

namespace LilacFlower
{
    partial class Form1
    {
        /// <summary>
        /// 
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows フォーム デザイナーで生成されたコード

        /// <summary>
        /// 
        /// 
        /// </summary>
        private void InitializeComponent()
        {
            this.mainPanel = new System.Windows.Forms.Panel();
            this.modePicture = new System.Windows.Forms.PictureBox();
            this.difficultySelection = new System.Windows.Forms.ComboBox();
            this.txtLabel = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.startbtn = new System.Windows.Forms.Button();
            this.addPicturebtn = new System.Windows.Forms.Button();
            this.pictureShowListBox = new System.Windows.Forms.ListBox();
            ((System.ComponentModel.ISupportInitialize)(this.modePicture)).BeginInit();
            this.SuspendLayout();
            // 
            // mainPanel
            // 
            this.mainPanel.Location = new System.Drawing.Point(151, 14);
            this.mainPanel.Name = "mainPanel";
            this.mainPanel.Size = new System.Drawing.Size(500, 500);
            this.mainPanel.TabIndex = 0;
            // 
            // modePicture
            // 
            this.modePicture.Location = new System.Drawing.Point(12, 12);
            this.modePicture.Name = "modePicture";
            this.modePicture.Size = new System.Drawing.Size(120, 120);
            this.modePicture.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
            this.modePicture.TabIndex = 0;
            this.modePicture.TabStop = false;
            this.modePicture.Click += new System.EventHandler(this.modePicture_Click);
            // 
            // difficultySelection
            // 
            this.difficultySelection.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.difficultySelection.FormattingEnabled = true;
            this.difficultySelection.Items.AddRange(new object[] {
            "简单(3*3)",
            "中等(5*5)",
            "困难(7*7)"});
            this.difficultySelection.Location = new System.Drawing.Point(45, 160);
            this.difficultySelection.Name = "difficultySelection";
            this.difficultySelection.Size = new System.Drawing.Size(88, 20);
            this.difficultySelection.TabIndex = 0;
            // 
            // txtLabel
            // 
            this.txtLabel.AutoS
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值