基于C#程序设计的扫雷冲关游戏开发 毕业论文(7)

2020-08-21 11:35

{

int position_x = rand.Next(hang); int position_y = rand.Next(lie);

if (button[position_x, position_y].Youlei == 0) {

button[position_x, position_y].Youlei = 1;

} else

i = i - 1; }

}

//判断点开的这个按钮周围8个中有几个地雷

private int Getdilei(int row, int col)//x代表行D,y代表列 {

int i, j; int around = 0;

int minRow = (row == 0) ? 0 : row - 1; int maxRow = row + 2;

int minCol = (col == 0) ? 0 : col - 1; int maxCol = col + 2;

for (i = minRow; i < maxRow; i++) {

for (j = minCol; j < maxCol; j++) {

if (!(i >= 0 && i = 0 && j < hang))//判断是否在扫|雷区域,有无越界

continue;

if (button[i, j].Youlei == 1) around++; } }

return around; }

//以下递归扫雷,向周围八个发散的递归查找 private void Saolei(int row, int col) {

int minrow1 = (row == 0) ? 0 : row - 1; int mincol1 = (col == 0) ? 0 : col - 1; int maxrow1 = row + 2;

24

int maxcol1 = col + 2;

int leishuliang = Getdilei(row, col); if (leishuliang == 0) {

button[row, col].Enabled = false; for (int m = minrow1; m < maxrow1; m++) {

for (int n = mincol1; n < maxcol1; n++) {

if (!(m >= 0 && m < hang && n >= 0 && n < lie)) continue;

if (!(m == row && n == col) && button[m, n].Enabled == true) Saolei(m, n);

button[m, n].Enabled = false;

button[m, n].Text = Getdilei(m, n).ToString(); if (button[m, n].Text == \) button[m, n].Text = string.Empty; }

} }

}

// 判断是否扫完地雷 private bool Win() {

int zongshu = 0;

for (int i = 0; i < hang; i++) {

for (int j = 0; j < lie; j++) {

if (button[i, j].Youlei == 1 && Convert.ToInt16(button[i, j].Tag) == 1) zongshu++;

}

}

if (zongshu == leishu) return true; else

return false;

}

25

//private void Showlei() //{

// for (int i = 0; i < hang; i++) // {

// for (int j = 0; j < lie; j++) // if (button[i, j].Youlei == 1) // {

// button[i, j].BackgroundImage = Image.FromFile(dileiimage); // }

// }

//}

private void xianshi() {

int l = 0;

for (int i = 0; i < hang; i++) {

for (int j = 0; j < lie; j++) {

if (button[i, j].Youlei == 1) {

button[i, j].BackgroundImage = Image.FromFile(shibai); l++;

//MessageBox.Show(button[i,j].Youlei.ToString()); } } }

}

//每次按开始按钮时所有方块复原- public void Fuyuan() {

for (int i = 0; i < hang; i++) {

for (int j = 0; j < lie; j++) {

button[i, j].Tag = 0; button[i, j].Enabled = true; button[i, j].Text = string.Empty; button[i, j].BackgroundImage = null; if (button[i, j].Youlei == 1)

26

button[i, j].Youlei = 0; }

} Bulei(); yongshi = 0; over = false; restlie = leishu; timer1.Start(); label4.Text = \秒?\;

lei.Text = restlie.ToString() + \颗?\;

button1.BackgroundImage = Image.FromFile(xiaolian); }

//定义timer组件的Tick事件

private void timer1_Tick(object sender, EventArgs e) {

yongshi++;

label4.Text = yongshi.ToString() + \秒?\; if (yongshi >= 60) timer1.Enabled = false; }

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) {

this.Close(); }

private void 中级ToolStripMenuItem_Click(object sender, EventArgs e) {

foreach (Button i in button) {

this.Controls.Remove(i); //i.Dispose(); }

start(40,16,16); ci = 1; zong = 5; fuli(); Fuyuan(); lei.Left=290; button1.Left = 150;

this.Size = new Size(330,433);

27

}

private void 初级ToolStripMenuItem_Click(object sender, EventArgs e) {

foreach (Button i in button) {

this.Controls.Remove(i); //i.Dispose(); }

start(10,9,9); ci = 1; zong = 5; fuli(); Fuyuan();

this.Size = new Size(190,293); }

private void 高级ToolStripMenuItem_Click(object sender, EventArgs e) {

foreach (Button i in button) {

this.Controls.Remove(i); //i.Dispose(); }

start(99,23,23); ci = 1; zong = 2; fuli();

lei.Left = 430; button1.Left =218; Fuyuan();

this.Size = new Size(470, 433); }

private void start(int a,int b,int c) {

restlie =Leishu=a; lie = b; hang = c;

label4.Text = \秒?\;

lei.Text = restlie.ToString() + \颗?\; timer1.Enabled = true;

button1.BackgroundImage = Image.FromFile(xiaolian); Leizheng(); Bulei();

28


基于C#程序设计的扫雷冲关游戏开发 毕业论文(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:当前中学语文课堂教学存在的主要问题及对策

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: