目录1 需求分析 (2)2 概要设计 (2)2.1 程序流程 (2)2.2 系统模块 (3)2.3 各模块功能 (3)3 详细设计 (4)3.1 主界面详细设计 (4)3.2 第一关详细设计 (5)3.3 第二关详细设计 (7)3.4 第三关详细设计 (10)3.5 第四关详细设计 (12)4 调试分析 (17)5 用户使用说明 (17)6 测试结果 (19)7 附录 (22)1 需求分析程序任务为一个鼠标小游戏,游戏规则为用户控制鼠标通过程序所给的路径抵达终点后游戏进入下一关,如果指针在移动过程都离开路径则游戏失败鼠标退回起点重新开始。
用户可以通过此游戏提高自己对鼠标的控制能力。
2 概要设计2.1程序流程游戏设有四关,每一关通过则进入下一关,直到通过最后一关(第四关),或者用户中途退出,游戏结束。
图1.1程序流程图2.2系统模块程序共分5个模块即主界面、第一关、第二关、第三关、第四关模块。
2.3各模块功能主界面:完成游戏的开启,以及游戏的选关功能。
第一关:完成第一关游戏的功能。
第二关:完成第二关游戏的功能。
第三关:完成第三关游戏的功能。
第四关:完成第四关游戏的功能。
3 详细设计3.1 主界面模块设计private void 开始游戏ToolStripMenuItem_Click(object sender, EventArgs e)//开始游戏{Form2 childform1 = new Form2(); //第一关界面新建childform1.Show();int x = this.Left + Width / 2;int y =this.Top+ (int)( Height * 0.95);Cursor.Position = new Point(x,y);}private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)//退出游戏{this.Close();}private void 第一关ToolStripMenuItem_Click(object sender, EventArgs e)//选择第一关{Form2 childform1 = new Form2();childform1.Show();int x = this.Left + Width / 2;int y = this.Top + (int)(Height * 0.93);Cursor.Position = new Point(x, y);}private void 第二关ToolStripMenuItem_Click(object sender, EventArgs e)//选择第二关{Form3 childform2 = new Form3();childform2.Show();int x = this.Left + (int)(Width * 0.95);int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}private void 第三关ToolStripMenuItem_Click(object sender, EventArgs e)//选择第三关{Form4 childform3 = new Form4();childform3.Show();int x = this.Left + (int)(Width * 0.05);int y = this.Top + (int)(Height * 0.9);Cursor.Position = new Point(x, y);}private void 第四关ToolStripMenuItem_Click(object sender, EventArgs e)//选择第四关{Form5 childform4 = new Form5();childform4.Show();int x = this.Left + (int)(Width * 0.5);int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}3.2 第一关模块设计图3.2.1黑色部分大的panel控件,白色与黄色的部分是属于picturebox控件。
private void panel1_MouseEnter(object sender, EventArgs e)//当指针移入黑色(panel)部分所触发事件{string message = "要继续吗?";//游戏结束,询问是否继续string caption = "游戏结束";MessageBoxButtons buttons = MessageBoxButtons.YesNo;DialogResult result;// Displays the MessageBox.result = MessageBox.Show(this, message, caption, buttons,MessageBoxIcon.Question);if (result == DialogResult.No)//否,退出游戏{// Closes the parent form.this.Close();}int x = this.Left + Width / 2;//继续游戏,指针回到起点位置int y = this.Top + (int)(Height * 0.93);Cursor.Position = new Point(x, y);}private void pictureBox3_MouseEnter(object sender, EventArgs e)//鼠标移入黄色的{Form3 form3 = new Form3();//新建第三关界面this.Close();//第一关界面退出form3.Show();//显示第二关}private void Form2_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar.ToString() == "+" || e.KeyChar.ToString() == "=")//按“+”键进入下一关{Form3 form3 = new Form3();//新建第二关,本关结束this.Close();form3.Show();int x = this.Left + (int)(Width * 0.95);int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}}private void Form2_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode.ToString() == "Escape")//按“Esc”键退出游戏{this.Close();}}3.2第二关模块设计图3.2.1private void panel1_MouseEnter(object sender, EventArgs e)//游戏失败后询问模块通第一关{string message = "要继续吗?";string caption = "游戏结束";MessageBoxButtons buttons = MessageBoxButtons.YesNo;DialogResult result;// Displays the MessageBox.result = MessageBox.Show(this, message, caption, buttons,MessageBoxIcon.Question);if (result == DialogResult.No){// Closes the parent form.this.Close();}int x = this.Left + (int)(Width *0.95);int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}private void pictureBox10_MouseEnter(object sender, EventArgs e)//抵达黄色终点事件{Form4 form4 = new Form4();this.Close();form4.Show();}private void Form3_KeyPress(object sender, KeyPressEventArgs e)//上一关下一关事件同第一关{if (e.KeyChar.ToString() == "-")//上一关{Form2 form2 = new Form2();//新建上一关窗口this.Close();form2.Show();int x = this.Left + Width / 2;//指针回到上一关初始位置int y = this.Top + (int)(Height * 0.93);Cursor.Position = new Point(x, y);}if (e.KeyChar.ToString() == "+" || e.KeyChar.ToString() == "=") {Form4 form4 = new Form4();//新建下一关窗口this.Close();form4.Show();int x = this.Left + (int)(Width * 0.05);//指针移动到下一关初始位置int y = this.Top + (int)(Height * 0.9);Cursor.Position = new Point(x, y);}if (e.KeyChar.ToString() == "ESC"){this.Close();}}private void Form3_KeyDown(object sender, KeyEventArgs e)//退出游戏同第一关{if (e.KeyCode.ToString() == "Escape"){this.Close();}}3.3第三关模块设计图3.3.1private void panel1_MouseEnter(object sender, EventArgs e)//游戏失败窗口与前几关相同{string message = "要继续吗?";string caption = "游戏结束";MessageBoxButtons buttons = MessageBoxButtons.YesNo;DialogResult result;// Displays the MessageBox.result = MessageBox.Show(this, message, caption, buttons,MessageBoxIcon.Question);if (result == DialogResult.No){// Closes the parent form.this.Close();}int x = this.Left + (int)(Width * 0.05);int y = this.Top + (int)(Height * 0.9);Cursor.Position = new Point(x, y);}private void pictureBox13_MouseEnter(object sender, EventArgs e)//过关后事件{Form5 form5 = new Form5();//新建第四关窗口this.Close();form5.Show();}private void Form4_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar.ToString() == "-"){Form3 form3 = new Form3();//新建上一关窗口this.Close();form3.Show();int x = this.Left + (int)(Width * 0.95);//鼠标回到上一关起始位置int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}if (e.KeyChar.ToString() == "+" || e.KeyChar.ToString() == "=") {Form5 form5 = new Form5();//新建下一关窗口this.Close();form5.Show();int x = this.Left + (int)(Width * 0.5);//鼠标移到下一关的起始位置int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y);}}private void Form4_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode.ToString() == "Escape")//按“Esc”键退出游戏{this.Close();}}3.4第四关模块设计开启地图前:图3.4.1 开启隐藏地图后:图3.4.2private void pictureBox66_MouseEnter_1(object sender, EventArgs e)//鼠标移入指定模块前先不可见{pictureBox65.Visible = false;pictureBox56.Visible = true;pictureBox67.Visible = true;}private void pictureBox56_MouseEnter(object sender, EventArgs e)//将隐藏的路劲显示{pictureBox57.Visible = true;pictureBox58.Visible = true;pictureBox59.Visible = true;pictureBox60.Visible = true;pictureBox61.Visible = true;pictureBox62.Visible = true;pictureBox63.Visible = true;pictureBox64.Visible = true;pictureBox1.Visible = true;pictureBox2.Visible = true;pictureBox3.Visible = true;}private void pictureBox1_MouseEnter(object sender, EventArgs e)//第一条个隐藏的路显示{pictureBox36.Visible = true;pictureBox37.Visible = true;pictureBox38.Visible = true;pictureBox39.Visible = true;pictureBox40.Visible = true;pictureBox41.Visible = true;pictureBox42.Visible = true;pictureBox43.Visible = true;pictureBox44.Visible = true;pictureBox45.Visible = true;pictureBox46.Visible = true;pictureBox47.Visible = true;pictureBox48.Visible = true;pictureBox49.Visible = true;pictureBox50.Visible = true;pictureBox51.Visible = true;pictureBox52.Visible = true;pictureBox53.Visible = true;pictureBox54.Visible = true;pictureBox55.Visible = true;pictureBox71.Visible = true;pictureBox72.Visible = true;pictureBox73.Visible = true;pictureBox74.Visible = true;pictureBox75.Visible = true;}private void pictureBox2_MouseEnter(object sender, EventArgs e)//第二条路事件{pictureBox59.Visible = false;}private void pictureBox3_MouseEnter(object sender, EventArgs e)//第三条路事件{pictureBox76.Visible = true;pictureBox77.Visible = true;pictureBox78.Visible = true;pictureBox79.Visible = true;pictureBox80.Visible = true;pictureBox81.Visible = true;}private void pictureBox68_MouseEnter_1(object sender, EventArgs e)//游戏通关事件{string message = "恭喜你!";string caption = "恭喜你!打通全关";MessageBoxButtons buttons = MessageBoxButtons.OK;DialogResult result;// Displays the MessageBox.result = MessageBox.Show(this, message, caption, buttons,rmation);if (result == DialogResult.No){// Closes the parent form.this.Close();}}private void panel1_MouseEnter(object sender, EventArgs e)//游戏失败事件{string message = "要继续吗?";string caption = "游戏结束";MessageBoxButtons buttons = MessageBoxButtons.YesNo;DialogResult result;// Displays the MessageBox.result = MessageBox.Show(this, message, caption, buttons,MessageBoxIcon.Question);if (result == DialogResult.No){// Closes the parent form.this.Close();}int x = this.Left + (int)(Width * 0.5);int y = this.Top + (int)(Height * 0.2);Cursor.Position = new Point(x, y); //继续游戏回到第四关起点}4 调试分析调试过程中所遇到的问题及解决方法(1)Esc的键盘事件开始采用Keypress发现没有该事件,后来改用Keydown 事件解决了这一问题(2)第四关的设计比较复杂,通过鼠标的movein事件来控制对相应picturebox的显示和隐藏,用了比较多的panel来设计路径。