求助拼图游戏的关卡设置问题

凉岑玉 2010-04-29 01:14:07
代码如下:
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();


}

}
}
//我想在完成一关之后再重新的到一张图片的拼图~也就是的到新的一关~不知道怎么做~希望大家指点!!
...全文
72 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
凉岑玉 2010-04-29
  • 打赏
  • 举报
回复
我是在界面里用了ImageBox控件~然后传图片上去的~要用好什么样的方法可以调用到下一个ImageBox里面的图片?
g394594141 2010-04-29
  • 打赏
  • 举报
回复
没看见你是在哪里导入图片的,你要先定一个函数,导入另外一张图片。
当你游戏胜利后,就调用那个函数即可。但是注意你要清空你上以上图片的变量,比如你那个存图片的数组等等
lexfu 2010-04-29
  • 打赏
  • 举报
回复
LZ你那不是有btnPlay_Click的事件么,不能生成新的图片?
要是不想点按钮生成的话,可以调用Button.PerformClick()方法

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧