求助拼图游戏的关卡设置问题
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PinTu2
{
public partial class MainForm : Form
{
int a;
public MainForm()
{
InitializeComponent();
}
Label[,] arrLbl = new Label[3, 3];
int unRow = 0, unCol = 0;
bool playing = false;
private void MainForm_Load(object sender, EventArgs e)
{
this.SuspendLayout();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Label lbl = new Label();
lbl.Text = "";
lbl.AutoSize = false;
lbl.Size = new Size(80, 80);
lbl.Location = new Point(j * 80, i * 80);
lbl.ImageList = imageList1;
lbl.Click += new System.EventHandler(this.lblPic_Click);
panel1.Controls.Add(lbl);
arrLbl[i, j] = lbl;
}
}
this.ResumeLayout();
}
private void btnPlay_Click(object sender, EventArgs e)
{
a = 0;
arrLbl[unRow, unCol].Visible = true;
int[] arrNum ={ 0, 1, 2, 3, 4, 5, 6, 7, 8 };
Random rm = new Random();
for (int i = 0; i < 8; i++)
{
int rmNum = rm.Next(i, 9);
int temp = arrNum[i];
arrNum[i] = arrNum[rmNum];
arrNum[rmNum] = temp;
}
for (int i = 0; i < 9; i++)
{
arrLbl[i / 3, i % 3].ImageIndex = arrNum[i];
arrLbl[i / 3, i % 3].BorderStyle = BorderStyle.FixedSingle;
}
int cover = rm.Next(0, 9);
unRow = cover / 3;
unCol = cover % 3;
arrLbl[unRow, unCol].Visible = false;
playing = true;
}
private void lblPic_Click(object sender, EventArgs e)
{
a++;
if (!playing)
{
return;
}
int row = ((Label)sender).Top / 80;
int col = ((Label)sender).Left / 80;
if (Math.Abs(row - unRow) + Math.Abs(col - unCol) == 1)
{
int temp = arrLbl[unRow, unCol].ImageIndex;
arrLbl[unRow, unCol].ImageIndex = arrLbl[row, col].ImageIndex;
arrLbl[row, col].ImageIndex = temp;
arrLbl[unRow, unCol].Visible = true;
arrLbl[row, col].Visible = false;
unRow = row;
unCol = col;
}
for (int i = 0; i < 9; i++)
{
if (arrLbl[i / 3, i % 3].ImageIndex != i)
{
break;
}
if (i == 8)
{
arrLbl[unRow, unCol].Visible = true;
foreach (Label lbl in arrLbl)
{
lbl.BorderStyle = BorderStyle.None;
}
playing = false;
MessageBox.Show("恭喜你通过了游戏!", "烧煤小姐",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
label2.Text = a.ToString();
}
}
}
//我想在完成一关之后再重新的到一张图片的拼图~也就是的到新的一关~不知道怎么做~希望大家指点!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace PinTu2
{
public partial class MainForm : Form
{
int a;
public MainForm()
{
InitializeComponent();
}
Label[,] arrLbl = new Label[3, 3];
int unRow = 0, unCol = 0;
bool playing = false;
private void MainForm_Load(object sender, EventArgs e)
{
this.SuspendLayout();
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Label lbl = new Label();
lbl.Text = "";
lbl.AutoSize = false;
lbl.Size = new Size(80, 80);
lbl.Location = new Point(j * 80, i * 80);
lbl.ImageList = imageList1;
lbl.Click += new System.EventHandler(this.lblPic_Click);
panel1.Controls.Add(lbl);
arrLbl[i, j] = lbl;
}
}
this.ResumeLayout();
}
private void btnPlay_Click(object sender, EventArgs e)
{
a = 0;
arrLbl[unRow, unCol].Visible = true;
int[] arrNum ={ 0, 1, 2, 3, 4, 5, 6, 7, 8 };
Random rm = new Random();
for (int i = 0; i < 8; i++)
{
int rmNum = rm.Next(i, 9);
int temp = arrNum[i];
arrNum[i] = arrNum[rmNum];
arrNum[rmNum] = temp;
}
for (int i = 0; i < 9; i++)
{
arrLbl[i / 3, i % 3].ImageIndex = arrNum[i];
arrLbl[i / 3, i % 3].BorderStyle = BorderStyle.FixedSingle;
}
int cover = rm.Next(0, 9);
unRow = cover / 3;
unCol = cover % 3;
arrLbl[unRow, unCol].Visible = false;
playing = true;
}
private void lblPic_Click(object sender, EventArgs e)
{
a++;
if (!playing)
{
return;
}
int row = ((Label)sender).Top / 80;
int col = ((Label)sender).Left / 80;
if (Math.Abs(row - unRow) + Math.Abs(col - unCol) == 1)
{
int temp = arrLbl[unRow, unCol].ImageIndex;
arrLbl[unRow, unCol].ImageIndex = arrLbl[row, col].ImageIndex;
arrLbl[row, col].ImageIndex = temp;
arrLbl[unRow, unCol].Visible = true;
arrLbl[row, col].Visible = false;
unRow = row;
unCol = col;
}
for (int i = 0; i < 9; i++)
{
if (arrLbl[i / 3, i % 3].ImageIndex != i)
{
break;
}
if (i == 8)
{
arrLbl[unRow, unCol].Visible = true;
foreach (Label lbl in arrLbl)
{
lbl.BorderStyle = BorderStyle.None;
}
playing = false;
MessageBox.Show("恭喜你通过了游戏!", "烧煤小姐",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
label2.Text = a.ToString();
}
}
}
//我想在完成一关之后再重新的到一张图片的拼图~也就是的到新的一关~不知道怎么做~希望大家指点!!
...全文
相关推荐
基于Android的拼图游戏,有关卡
基于Android的拼图游戏,有关卡,源代码直接运行
pgzrun 拼图游戏制作过程详解(总纲)
使用pgzrun模块以及一些Python自带的标准模块编写拼图游戏。
JS版本拼图游戏,可自定义关卡内容及关卡数
JS版本拼图游戏。 1.一共五关,可以设置更多关卡 2.可以自定义每一关卡的拼图图片内容 3.开始图片随机打乱 4.采用JQuery框架 5.随机代码可见 6.关卡设计建议采用600*600图片 7.设置多关卡方法:man? (?代表对应关卡) 付费用户可联系作者咨询
拼图游戏 (源码+所有文件)
萌新做的一个简单的Java拼图游戏 启动类:pers.sept.jigsaw1.swing下的MianFrame 其他有主方法的是测试类。 多线程。 下拉列表选择数字可以切换关卡图片,最后的“+”,可以添自己的图片到关卡中。 设有背景音乐 有一键通过按钮 等等,块下载去看看吧。
微信小游戏之拼图游戏
本程序可在浏览器中打开可在JS文件中设置难度、关卡以及图片等,可以通过设置本机IIS,将本机作为服务器,打开网页,方便快捷。


