麻烦大家看看我这程序问题出在哪?
namespace fifth{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label2.Text = "";
int key = Convert.ToInt32(textBox1.Text);
int[] roomlist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] keylist = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for (int i = 0; i < 10; i++)
{
openroom(keylist, key, roomlist);
}
}
private int openroom(int[] keylist,int key,int[] roomlist)
{
for(int i=0;i<10;i++)
{
if (key == roomlist[i])
{
string a = "我是" + key + "的钥匙,能打开" + roomlist[i] + "房间的门。" ;
label2.Text = label2.Text + a ;
keylist[key - 1] = -1;
key=ownkey(roomlist,roomlist[i],keylist);
}
}
return key;
}
private int ownkey(int[] roomlist,int room,int[] keylist)
{
Random rd = new Random();
int key=0;
Boolean b = true;
while(b)
{
key = (int)rd.Next(0, 11);
for (int i = 1; i < 10;i++ )
{
if (key == keylist[i])
{
b = false;
break;
}
}
}
string a = "我是房间" + room + ",我有" + key + "钥匙。";
label2.Text =label2.Text +a + "\n";
roomlist[room - 1] = -1;
return key;
}
}
}